--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A node ??? apt-proxy
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Apt-Proxy Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Node???AptProxy extends BaseNodeAptProxy implements AptProxyter {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $proxyInstance An instance of a AptProxyter class
+ */
+ public final static function createNode???AptProxy () {
+ // Get new instance
+ $proxyInstance = new Node???AptProxy();
+
+ // Return the prepared instance
+ return $proxyInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the apt-proxy. This step does also apply provided
+ * command-line arguments stored in the request instance. You should now
+ * get it from calling $this->getRequestInstance().
+ *
+ * @return void
+ */
+ public function doBootstrapping () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Add some apt-proxy-specific filters
+ *
+ * @param $controllerInstance An object of a Controller instance
+ * @param $responseInstance An object of a Responseable instance
+ * @return void
+ */
+ public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general NodeAptProxy class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 BaseNodeAptProxy extends BaseHubSystem {
+ /**
+ * Whether this apt-proxy is active
+ */
+ private $isActive = FALSE;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Enables/disables the apt-proxy (just sets a flag)
+ *
+ * @param $version Version number of this apt-proxy
+ * @return void
+ */
+ public final function enableIsActive ($isActive = TRUE) {
+ $this->isActive = (bool) $isActive;
+ }
+
+ /**
+ * Determines whether the apt-proxy is active
+ *
+ * @return $isActive Whether the apt-proxy is active
+ */
+ public final function isActive () {
+ return $this->isActive;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A node console apt-proxy
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 NodeConsoleAptProxy extends BaseNodeAptProxy implements AptProxy, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $proxyInstance An instance of a AptProxy class
+ */
+ public final static function createNodeConsoleAptProxy () {
+ // Get new instance
+ $proxyInstance = new NodeConsoleAptProxy();
+
+ // Return the prepared instance
+ return $proxyInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the apt-proxy. This step does also apply provided
+ * command-line arguments stored in the request instance. You should now
+ * get it from calling $this->getRequestInstance().
+ *
+ * @return void
+ */
+ public function doBootstrapping () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ // Get the app instance (for shortening our code)
+ $app = $this->getApplicationInstance();
+
+ // Output all lines
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - An apt-proxy connection helper');
+ self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2012 Apt-Proxy Developer Team');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
+ self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
+ self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ }
+
+ /**
+ * Add some apt-proxy-specific filters
+ *
+ * @param $controllerInstance An object of a Controller instance
+ * @param $responseInstance An object of a Responseable instance
+ * @return void
+ */
+ public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? block class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Block extends BaseBlock implements === {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $blockInstance An instance of a === class
+ */
+ public final static function create???Block () {
+ // Get new instance
+ $blockInstance = new ???Block();
+
+ // Return the prepared instance
+ return $blockInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Block class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 BaseBlock extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Hash block class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 HashBlock extends BaseBlock implements Minable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $blockInstance An instance of a Minable class
+ */
+ public final static function createHashBlock () {
+ // Get new instance
+ $blockInstance = new HashBlock();
+
+ // Return the prepared instance
+ return $blockInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A filter chain for processing network packages (or better messages)
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageFilterChain extends FilterChain {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $chainInstance An instance of this class
+ */
+ public static final function createPackageFilterChain () {
+ // Get a new instance
+ $chainInstance = new PackageFilterChain();
+
+ // Return the prepared instance
+ return $chainInstance;
+ }
+
+ /**
+ * Processes the given raw message content through all filters
+ *
+ * @param $messageData Raw message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @todo This may be slow if a message with a lot tags arrived
+ */
+ public function processMessage (array $messageData, Receivable $packageInstance) {
+ // Get all filters and "run" them
+ foreach ($this->getFilters() as $filterInstance) {
+ // Try to process it
+ try {
+ $filterInstance->processMessage($messageData, $packageInstance);
+ } catch (FilterChainException $e) {
+ // This exception can be thrown to just skip any further processing
+ self::createDebugInstance(__CLASS__)->debugOutput('Failed to execute lase filter ' . $filterInstance->__toString() . ': ' . $e->getMessage());
+ break;
+ }
+ } // END - foreach
+ }
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Get all filters and "run" them
+ foreach ($this->getPostFilters() as $filterInstance) {
+ // Try to process it
+ try {
+ $filterInstance->postProcessMessage($packageInstance);
+ } catch (FilterChainException $e) {
+ // This exception can be thrown to just skip any further processing
+ self::createDebugInstance(__CLASS__)->debugOutput('Failed to execute lase filter ' . $filterInstance->__toString() . ': ' . $e->getMessage());
+ break;
+ }
+ } // END - foreach
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A node ??? chat
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Node???Chat extends BaseNodeChat implements Chatter {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $chatInstance An instance of a Chatter class
+ */
+ public final static function createNode???Chat () {
+ // Get new instance
+ $chatInstance = new Node???Chat();
+
+ // Return the prepared instance
+ return $chatInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the chatter. This step does also apply provided
+ * command-line arguments stored in the request instance. You should now
+ * get it from calling $this->getRequestInstance().
+ *
+ * @return void
+ */
+ public function doBootstrapping () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Add some chatter-specific filters
+ *
+ * @param $controllerInstance An object of a Controller instance
+ * @param $responseInstance An object of a Responseable instance
+ * @return void
+ */
+ public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general NodeChat class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 BaseNodeChat extends BaseHubSystem {
+ /**
+ * Whether this Chatter is active
+ */
+ private $isActive = FALSE;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Enables/disables the chatter (just sets a flag)
+ *
+ * @param $version Version number of this chatter
+ * @return void
+ */
+ public final function enableIsActive ($isActive = TRUE) {
+ $this->isActive = (bool) $isActive;
+ }
+
+ /**
+ * Determines whether the chatter is active
+ *
+ * @return $isActive Whether the chatter is active
+ */
+ public final function isActive () {
+ return $this->isActive;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A node console chat
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 NodeConsoleChat extends BaseNodeChat implements Chatter, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $chatInstance An instance of a Chatter class
+ */
+ public final static function createNodeConsoleChat () {
+ // Get new instance
+ $chatInstance = new NodeConsoleChat();
+
+ // Return the prepared instance
+ return $chatInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the chatter. This step does also apply provided
+ * command-line arguments stored in the request instance. You should now
+ * get it from calling $this->getRequestInstance().
+ *
+ * @return void
+ */
+ public function doBootstrapping () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ // Get the app instance (for shortening our code)
+ $app = $this->getApplicationInstance();
+
+ // Output all lines
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - A telnet connection helper');
+ self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2012 Chat Developer Team');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
+ self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
+ self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ }
+
+ /**
+ * Add some chatter-specific filters
+ *
+ * @param $controllerInstance An object of a Controller instance
+ * @param $responseInstance An object of a Responseable instance
+ * @return void
+ */
+ public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ???
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ??? extends BaseFrameworkSystem implements === {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $!!!Instance An instance of a === class
+ */
+ public final static function create??? () {
+ // Get new instance
+ $!!!Instance = new ???();
+
+ // Return the prepared instance
+ return $!!!Instance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general ??? class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Base??? extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general hub system class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubSystem extends BaseFrameworkSystem {
+ // Exception codes
+ const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x900;
+ const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x901;
+ const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0x902;
+ const EXCEPTION_INVALID_CONNECTION_TYPE = 0x903;
+ const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED = 0x904;
+ const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4 = 0x905;
+ const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0x906;
+ const EXCEPTION_REQUEST_NOT_ACCEPTED = 0x907;
+ const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED = 0x908;
+ const EXCEPTION_MULTIPLE_MESSAGE_SENT = 0x909;
+ const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED = 0x90a;
+ const EXCEPTION_INVALID_UNL = 0x90b;
+
+ // Message status codes
+ const MESSAGE_STATUS_CODE_OKAY = 'OKAY';
+
+ /**
+ * Separator for all bootstrap node entries
+ */
+ const BOOTSTRAP_NODES_SEPARATOR = ';';
+
+ /**
+ * An instance of a node
+ */
+ private $nodeInstance = NULL;
+
+ /**
+ * A network package handler instance
+ */
+ private $packageInstance = NULL;
+
+ /**
+ * A Receivable instance
+ */
+ private $receiverInstance = NULL;
+
+ /**
+ * Listener pool instance
+ */
+ private $listenerPoolInstance = NULL;
+
+ /**
+ * Fragmenter instance
+ */
+ private $fragmenterInstance = NULL;
+
+ /**
+ * Assembler instance
+ */
+ private $assemblerInstance = NULL;
+
+ /**
+ * Info instance
+ */
+ private $infoInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Setter for network package handler instance
+ *
+ * @param $packageInstance The network package instance we shall set
+ * @return void
+ */
+ protected final function setPackageInstance (Deliverable $packageInstance) {
+ $this->packageInstance = $packageInstance;
+ }
+
+ /**
+ * Getter for network package handler instance
+ *
+ * @return $packageInstance The network package handler instance we shall set
+ */
+ protected final function getPackageInstance () {
+ return $this->packageInstance;
+ }
+
+ /**
+ * Setter for receiver instance
+ *
+ * @param $receiverInstance A Receivable instance we shall set
+ * @return void
+ */
+ protected final function setReceiverInstance (Receivable $receiverInstance) {
+ $this->receiverInstance = $receiverInstance;
+ }
+
+ /**
+ * Getter for receiver instance
+ *
+ * @return $receiverInstance A Receivable instance we shall get
+ */
+ protected final function getReceiverInstance () {
+ return $this->receiverInstance;
+ }
+
+ /**
+ * Setter for listener pool instance
+ *
+ * @param $listenerPoolInstance The new listener pool instance
+ * @return void
+ */
+ protected final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
+ $this->listenerPoolInstance = $listenerPoolInstance;
+ }
+
+ /**
+ * Getter for listener pool instance
+ *
+ * @return $listenerPoolInstance Our current listener pool instance
+ */
+ public final function getListenerPoolInstance () {
+ return $this->listenerPoolInstance;
+ }
+
+ /**
+ * Setter for fragmenter instance
+ *
+ * @param $fragmenterInstance A Fragmentable instance
+ * @return void
+ */
+ protected final function setFragmenterInstance (Fragmentable $fragmenterInstance) {
+ $this->fragmenterInstance = $fragmenterInstance;
+ }
+
+ /**
+ * Getter for fragmenter instance
+ *
+ * @return $fragmenterInstance A Fragmentable instance
+ */
+ protected final function getFragmenterInstance () {
+ return $this->fragmenterInstance;
+ }
+
+ /**
+ * Setter for assembler instance
+ *
+ * @param $assemblerInstance An instance of an Assembler class
+ * @return void
+ */
+ protected final function setAssemblerInstance (Assembler $assemblerInstance) {
+ $this->assemblerInstance = $assemblerInstance;
+ }
+
+ /**
+ * Getter for assembler instance
+ *
+ * @return $assemblerInstance An instance of an Assembler class
+ */
+ protected final function getAssemblerInstance () {
+ return $this->assemblerInstance;
+ }
+
+ /**
+ * Setter for info instance
+ *
+ * @param $infoInstance A ShareableInfo instance
+ * @return void
+ */
+ protected final function setInfoInstance (ShareableInfo $infoInstance) {
+ $this->infoInstance = $infoInstance;
+ }
+
+ /**
+ * Getter for info instance
+ *
+ * @return $infoInstance An instance of a ShareableInfo class
+ */
+ public final function getInfoInstance () {
+ return $this->infoInstance;
+ }
+
+ /**
+ * Setter for node id
+ *
+ * @param $nodeId The new node id
+ * @return void
+ */
+ protected final function setNodeId ($nodeId) {
+ // Set it config now
+ $this->getConfigInstance()->setConfigEntry('node_id', (string) $nodeId);
+ }
+
+ /**
+ * Getter for node id
+ *
+ * @return $nodeId Current node id
+ */
+ public final function getNodeId () {
+ // Get it from config
+ return $this->getConfigInstance()->getConfigEntry('node_id');
+ }
+
+ /**
+ * Setter for private key
+ *
+ * @param $privateKey The new private key
+ * @return void
+ */
+ protected final function setPrivateKey ($privateKey) {
+ // Set it config now
+ $this->getConfigInstance()->setConfigEntry('private_key', (string) $privateKey);
+ }
+
+ /**
+ * Getter for private key
+ *
+ * @return $privateKey Current private key
+ */
+ public final function getPrivateKey () {
+ // Get it from config
+ return $this->getConfigInstance()->getConfigEntry('private_key');
+ }
+
+ /**
+ * Setter for private key hash
+ *
+ * @param $privateKeyHash The new private key hash
+ * @return void
+ */
+ protected final function setPrivateKeyHash ($privateKeyHash) {
+ // Set it config now
+ $this->getConfigInstance()->setConfigEntry('private_key_hash', (string) $privateKeyHash);
+ }
+
+ /**
+ * Getter for private key hash
+ *
+ * @return $privateKeyHash Current private key hash
+ */
+ public final function getPrivateKeyHash () {
+ // Get it from config
+ return $this->getConfigInstance()->getConfigEntry('private_key_hash');
+ }
+
+ /**
+ * Setter for session id
+ *
+ * @param $sessionId The new session id
+ * @return void
+ */
+ protected final function setSessionId ($sessionId) {
+ $this->getConfigInstance()->setConfigEntry('session_id', (string) $sessionId);
+ }
+
+ /**
+ * Getter for session id
+ *
+ * @return $sessionId Current session id
+ */
+ public final function getSessionId () {
+ return $this->getConfigInstance()->getConfigEntry('session_id');
+ }
+
+ /**
+ * Constructs a callable method name from given socket error code. If the
+ * method is not found, a generic one is used.
+ *
+ * @param $errorCode Error code from socket_last_error()
+ * @return $handlerName Call-back method name for the error handler
+ * @throws UnsupportedSocketErrorHandlerException If the error handler is not implemented
+ */
+ protected function getSocketErrorHandlerFromCode ($errorCode) {
+ // Create a name from translated error code
+ $handlerName = 'socketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler';
+
+ // Is the call-back method there?
+ if (!method_exists($this, $handlerName)) {
+ // Please implement this
+ throw new UnsupportedSocketErrorHandlerException(array($this, $handlerName, $errorCode), self::EXCEPTION_UNSUPPORTED_ERROR_HANDLER);
+ } // END - if
+
+ // Return it
+ return $handlerName;
+ }
+
+ /**
+ * 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 $unlData A valid UNL data array
+ * @return void
+ * @throws InvalidSocketException If $socketResource is no socket resource
+ * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back
+ */
+ protected final function handleSocketError ($method, $line, $socketResource, array $unlData) {
+ // 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 UNL array
+ //* DEBUG-DIE: */ die(__METHOD__ . ':unlData=' . print_r($unlData, TRUE));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+
+ // 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, $unlData));
+
+ // Finally clear the error because it has been handled
+ socket_clear_error($socketResource);
+ }
+
+ /**
+ * Translates socket error codes into our own internal names which can be
+ * used for call-backs.
+ *
+ * @param $errorCode The error code from socket_last_error() to be translated
+ * @return $errorName The translated name (all lower-case, with underlines)
+ */
+ public function translateSocketErrorCodeToName ($errorCode) {
+ // Nothing bad happened by default
+ $errorName = BaseRawDataHandler::SOCKET_CONNECTED;
+
+ // Is the code a number, then we have to change it
+ switch ($errorCode) {
+ case 0: // Silently ignored, the socket is connected
+ break;
+
+ case 11: // "Resource temporary unavailable"
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_RESOURCE_UNAVAILABLE;
+ break;
+
+ case 32: // "Broken pipe"
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_BROKEN_PIPE;
+ break;
+
+ case 104: // "Connection reset by peer"
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_RESET_BY_PEER;
+ break;
+
+ case 107: // "Transport end-point not connected"
+ case 134: // On some (?) systems for 'transport end-point not connected'
+ // @TODO On some systems it is 134, on some 107?
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
+ break;
+
+ case 110: // "Connection timed out"
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_TIMED_OUT;
+ break;
+
+ case 111: // "Connection refused"
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED;
+ break;
+
+ case 113: // "No route to host"
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_NO_ROUTE_TO_HOST;
+ break;
+
+ case 114: // "Operation already in progress"
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS;
+ break;
+
+ case 115: // "Operation now in progress"
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_IN_PROGRESS;
+ break;
+
+ default: // Everything else <> 0
+ // Unhandled error code detected, so first debug it because we may want to handle it like the others
+ self::createDebugInstance(__CLASS__)->debugOutput('BASE-HUB[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode));
+
+ // Change it only in this class
+ $errorName = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
+ break;
+ }
+
+ // Return translated name
+ return $errorName;
+ }
+
+ /**
+ * Shuts down a given socket resource. This method does only ease calling
+ * the right visitor.
+ *
+ * @param $socketResource A valid socket resource
+ * @return void
+ */
+ public function shutdownSocket ($socketResource) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
+
+ // Set socket resource
+ $this->setSocketResource($socketResource);
+
+ // Get a visitor instance
+ $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
+
+ // Debug output
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
+
+ // Call the visitor
+ $this->accept($visitorInstance);
+ }
+
+ /**
+ * Half-shuts down a given socket resource. This method does only ease calling
+ * an other visitor than shutdownSocket() does.
+ *
+ * @param $socketResource A valid socket resource
+ * @return void
+ */
+ public function halfShutdownSocket ($socketResource) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
+
+ // Set socket resource
+ $this->setSocketResource($socketResource);
+
+ // Get a visitor instance
+ $visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class');
+
+ // Debug output
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
+
+ // Call the visitor
+ $this->accept($visitorInstance);
+ }
+
+ /**
+ * "Getter" for a printable state name
+ *
+ * @return $stateName Name of the node's state in a printable format
+ */
+ public final function getPrintableState () {
+ // Default is 'null'
+ $stateName = 'null';
+
+ // Get the state instance
+ $stateInstance = $this->getStateInstance();
+
+ // Is it an instance of Stateable?
+ if ($stateInstance instanceof Stateable) {
+ // Then use that state name
+ $stateName = $stateInstance->getStateName();
+ } // END - if
+
+ // Return result
+ return $stateName;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A command for the 'apt-proxy client' routine
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 HubConsoleAptProxyCommand extends BaseCommand implements Commandable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $commandInstance An instance a prepared command class
+ */
+ public static final function createHubConsoleAptProxyCommand (CommandResolver $resolverInstance) {
+ // Get new instance
+ $commandInstance = new HubConsoleAptProxyCommand();
+
+ // Set the application instance
+ $commandInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $commandInstance;
+ }
+
+ /**
+ * Executes the given command with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Try to create a AptProxyActivationTask or so
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a registry and the application instance from it
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ /*
+ * ----------------------- Bootstrapping phase ------------------------
+ * Try to bootstrap the node and pass the request instance to it for
+ * extra arguments which mostly override config entries or enable special
+ * features within the hub (none is ready at this development stage)
+ */
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
+ $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
+
+ // Get apt-proxy instance
+ $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
+
+ // Add some apt-proxy-specific filters
+ $proxyInstance->addExtraAptProxyFilters();
+
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
+
+ /*
+ * ----------------------------- Main loop ----------------------------
+ * This is the main loop. Queried calls should come back here very fast
+ * so the whole application runs on nice speed. This while-loop goes
+ * until the apt-proxy is no longer active or all tasks are killed.
+ */
+ while (($proxyInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
+ // Handle all tasks here
+ $handlerInstance->handleTasks();
+ } // END - while
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
+ }
+
+ /**
+ * Adds extra filters to the given controller instance
+ *
+ * @param $controllerInstance A controller instance
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @return void
+ * @todo Should we add some more filters?
+ */
+ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
+ // Add pre filters
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_php_requirements_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_initializer_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_welcome_teaser_filter'));
+
+ // Add bootstrap filters
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_bootstrap_task_handler_initializer_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_bootstrap_extra_bootstrapping_filter'));
+
+ // This is the last generic boostrap filter
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_bootstrap_generic_activation_filter'));
+
+ // Add shutdown filters
+ //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_shutdown_task_handler_filter'));
+
+ // This is the last generic shutdown filter
+ $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_shutdown_filter'));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A command for the 'chat client' routine
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 HubConsoleChatCommand extends BaseCommand implements Commandable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $commandInstance An instance a prepared command class
+ */
+ public static final function createHubConsoleChatCommand (CommandResolver $resolverInstance) {
+ // Get new instance
+ $commandInstance = new HubConsoleChatCommand();
+
+ // Set the application instance
+ $commandInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $commandInstance;
+ }
+
+ /**
+ * Executes the given command with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Try to create a ChatActivationTask or so
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a registry and the application instance from it
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ /*
+ * ----------------------- Bootstrapping phase ------------------------
+ * Try to bootstrap the node and pass the request instance to it for
+ * extra arguments which mostly override config entries or enable special
+ * features within the hub (none is ready at this development stage)
+ */
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
+ $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
+
+ // Get chat instance
+ $chatInstance = Registry::getRegistry()->getInstance('chat');
+
+ // Add some chat-specific filters
+ $chatInstance->addExtraChatFilters();
+
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
+
+ /*
+ * ----------------------------- Main loop ----------------------------
+ * This is the main loop. Queried calls should come back here very fast
+ * so the whole application runs on nice speed. This while-loop goes
+ * until the chat is no longer active or all tasks are killed.
+ */
+ while (($chatInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
+ // Handle all tasks here
+ $handlerInstance->handleTasks();
+ } // END - while
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
+ }
+
+ /**
+ * Adds extra filters to the given controller instance
+ *
+ * @param $controllerInstance A controller instance
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @return void
+ * @todo Should we add some more filters?
+ */
+ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
+ // Add pre filters
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('chat_php_requirements_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('chat_initializer_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('chat_welcome_teaser_filter'));
+
+ // Add bootstrap filters
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('chat_bootstrap_task_handler_initializer_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('chat_bootstrap_extra_bootstrapping_filter'));
+
+ // This is the last generic boostrap filter
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('chat_bootstrap_generic_activation_filter'));
+
+ // Add shutdown filters
+ //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('chat_shutdown_task_handler_filter'));
+
+ // This is the last generic shutdown filter
+ $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('chat_shutdown_filter'));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A command for the 'crawler client' routine
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 HubConsoleCrawlerCommand extends BaseCommand implements Commandable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $commandInstance An instance a prepared command class
+ */
+ public static final function createHubConsoleCrawlerCommand (CommandResolver $resolverInstance) {
+ // Get new instance
+ $commandInstance = new HubConsoleCrawlerCommand();
+
+ // Set the application instance
+ $commandInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $commandInstance;
+ }
+
+ /**
+ * Executes the given command with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Try to create a CrawlerActivationTask or so
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a registry and the application instance from it
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ /*
+ * ----------------------- Bootstrapping phase ------------------------
+ * Try to bootstrap the node and pass the request instance to it for
+ * extra arguments which mostly override config entries or enable special
+ * features within the hub (none is ready at this development stage)
+ */
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
+ $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
+
+ // Get crawler instance
+ $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
+
+ // Add some crawler-specific filters
+ $crawlerInstance->addExtraCrawlerFilters();
+
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
+
+ /*
+ * ----------------------------- Main loop ----------------------------
+ * This is the main loop. Queried calls should come back here very fast
+ * so the whole application runs on nice speed. This while-loop goes
+ * until the crawler is no longer active or all tasks are killed.
+ */
+ while (($crawlerInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
+ // Handle all tasks here
+ $handlerInstance->handleTasks();
+ } // END - while
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
+ }
+
+ /**
+ * Adds extra filters to the given controller instance
+ *
+ * @param $controllerInstance A controller instance
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @return void
+ * @todo Should we add some more filters?
+ */
+ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
+ // Add pre filters
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('crawler_php_requirements_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('crawler_initializer_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('crawler_welcome_teaser_filter'));
+
+ // Add bootstrap filters
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('crawler_bootstrap_task_handler_initializer_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('crawler_bootstrap_extra_bootstrapping_filter'));
+
+ // This is the last generic boostrap filter
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('crawler_bootstrap_generic_activation_filter'));
+
+ // Add shutdown filters
+ //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('crawler_shutdown_task_handler_filter'));
+
+ // This is the last generic shutdown filter
+ $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('crawler_shutdown_filter'));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A command for the 'cruncher client' routine
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 HubConsoleCruncherCommand extends BaseCommand implements Commandable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $commandInstance An instance a prepared command class
+ */
+ public static final function createHubConsoleCruncherCommand (CommandResolver $resolverInstance) {
+ // Get new instance
+ $commandInstance = new HubConsoleCruncherCommand();
+
+ // Set the application instance
+ $commandInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $commandInstance;
+ }
+
+ /**
+ * Executes the given command with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Try to create a CruncherActivationTask or so
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a registry and the application instance from it
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ /*
+ * ----------------------- Bootstrapping phase ------------------------
+ * Try to bootstrap the node and pass the request instance to it for
+ * extra arguments which mostly override config entries or enable special
+ * features within the hub (none is ready at this development stage)
+ */
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
+ $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
+
+ // Get cruncher instance
+ $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
+
+ // Add some cruncher-specific filters
+ $cruncherInstance->addExtraCruncherFilters();
+
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
+
+ /*
+ * ----------------------------- Main loop ----------------------------
+ * This is the main loop. Queried calls should come back here very fast
+ * so the whole application runs on nice speed. This while-loop goes
+ * until the cruncher is no longer active or all tasks are killed.
+ */
+ while (($cruncherInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
+ // Handle all tasks here
+ $handlerInstance->handleTasks();
+ } // END - while
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
+ }
+
+ /**
+ * Adds extra filters to the given controller instance
+ *
+ * @param $controllerInstance A controller instance
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @return void
+ * @todo Should we add some more filters?
+ */
+ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
+ // Add pre filters
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('cruncher_php_requirements_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('cruncher_initializer_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('cruncher_welcome_teaser_filter'));
+
+ // Add bootstrap filters
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('cruncher_bootstrap_task_handler_initializer_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('cruncher_bootstrap_extra_bootstrapping_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('cruncher_bootstrap_buffer_queue_initializer_filter'));
+
+ // This is the last generic boostrap filter
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('cruncher_bootstrap_generic_activation_filter'));
+
+ // Add shutdown filters
+ //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('cruncher_shutdown_task_handler_filter'));
+
+ // This is the last generic shutdown filter
+ $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('cruncher_shutdown_filter'));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A command for the 'main' routine
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubConsoleMainCommand extends BaseCommand implements Commandable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $commandInstance An instance a prepared command class
+ */
+ public static final function createHubConsoleMainCommand (CommandResolver $resolverInstance) {
+ // Get new instance
+ $commandInstance = new HubConsoleMainCommand();
+
+ // Set the application instance
+ $commandInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $commandInstance;
+ }
+
+ /**
+ * Executes the given command with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Try to create a HubActivationTask or so
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a registry and the application instance from it
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ /*
+ * ----------------------- Bootstrapping phase ------------------------
+ * Try to bootstrap the node and pass the request instance to it for
+ * extra arguments which mostly override config entries or enable special
+ * features within the hub (none is ready at this development stage)
+ */
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
+ $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
+
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Add some node-specific filters, e.g. announcement
+ $nodeInstance->addExtraNodeFilters();
+
+ /*
+ * -------------------------- Hub activation --------------------------
+ * Activates the node by doing some final preparation steps and setting
+ * the attribute $hubIsActive to TRUE.
+ */
+ $nodeInstance->activateNode($requestInstance, $responseInstance);
+
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
+
+ /*
+ * ----------------------------- Main loop ----------------------------
+ * This is the main loop. Queried calls should come back here very fast
+ * so the whole application runs on nice speed. This while-loop goes
+ * until the hub is no longer active or all tasks are killed.
+ */
+ while (($nodeInstance->isNodeActive()) && ($handlerInstance->hasTasksLeft())) {
+ // Handle all tasks here
+ $handlerInstance->handleTasks();
+ } // END - while
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
+ }
+
+ /**
+ * Adds extra filters to the given controller instance
+ *
+ * @param $controllerInstance A controller instance
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @return void
+ * @todo Should we add some more filters?
+ */
+ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
+ // Add pre filters
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_php_requirements_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_initializer_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_welcome_teaser_filter'));
+
+ // Add bootstrap filters
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_nodeid_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_sessionid_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_private_key_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_extra_bootstrapping_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_listener_pool_filter'));
+
+ // Add node activation filters
+ $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_task_handler_initializer_filter'));
+
+ // Add shutdown filters
+ $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_flush_node_list_filter'));
+ $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_task_handler_filter'));
+
+ // This is the last generic shutdown filter
+ $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_node_filter'));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A command for the 'miner client' routine
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Miner 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 HubConsoleMinerCommand extends BaseCommand implements Commandable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $commandInstance An instance a prepared command class
+ */
+ public static final function createHubConsoleMinerCommand (CommandResolver $resolverInstance) {
+ // Get new instance
+ $commandInstance = new HubConsoleMinerCommand();
+
+ // Set the application instance
+ $commandInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $commandInstance;
+ }
+
+ /**
+ * Executes the given command with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Try to create a MinerActivationTask or so
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a registry and the application instance from it
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ /*
+ * ----------------------- Bootstrapping phase ------------------------
+ * Try to bootstrap the node and pass the request instance to it for
+ * extra arguments which mostly override config entries or enable special
+ * features within the hub (none is ready at this development stage)
+ */
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
+ $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
+
+ // Get miner instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Add some miner-specific filters
+ $minerInstance->addExtraMinerFilters();
+
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
+
+ /*
+ * ----------------------------- Main loop ----------------------------
+ * This is the main loop. Queried calls should come back here very fast
+ * so the whole application runs on nice speed. This while-loop goes
+ * until the miner is no longer active or all tasks are killed.
+ */
+ while (($minerInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
+ // Handle all tasks here
+ $handlerInstance->handleTasks();
+ } // END - while
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
+ }
+
+ /**
+ * Adds extra filters to the given controller instance
+ *
+ * @param $controllerInstance A controller instance
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @return void
+ * @todo Should we add some more filters?
+ */
+ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
+ // Add pre filters
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('miner_php_requirements_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('miner_initializer_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('miner_welcome_teaser_filter'));
+
+ // Add bootstrap filters
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_task_handler_initializer_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_extra_bootstrapping_filter'));
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_buffer_queue_initializer_filter'));
+
+ // This is the last generic boostrap filter
+ $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_generic_activation_filter'));
+
+ // Add shutdown filters
+ //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('miner_shutdown_task_handler_filter'));
+
+ // This is the last generic shutdown filter
+ $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('miner_shutdown_filter'));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A command for the 'main' routine
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2015 City 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 HubHtmlIndexCommand extends BaseCommand implements Commandable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $commandInstance An instance a prepared command class
+ */
+ public static final function createHubHtmlIndexCommand (CommandResolver $resolverInstance) {
+ // Get new instance
+ $commandInstance = new HubHtmlIndexCommand();
+
+ // Set the application instance
+ $commandInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $commandInstance;
+ }
+
+ /**
+ * Executes the given command with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // This command doesn't handle any POST requests, so only handle get request
+ if ($requestInstance->isPostRequestMethod()) {
+ // Don't handle this here
+ $response->sendRequestMethodNotAllowed();
+
+ // Bail out
+ exit();
+ } // END - if
+
+ /*
+ * This is a generic HTML request, this means that a regular page with
+ * header, menu, content and footer shall be send to the client.
+ */
+ $this->sendGenericGetResponse($requestInstance, $responseInstance);
+ }
+
+ /**
+ * Adds extra filters to the given controller instance
+ *
+ * @param $controllerInstance A controller instance
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
+ // Add pre filters
+ //$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_php_requirements_filter'));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ???->node communicator class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 !!! Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???NodeCommunicator extends BaseCommunicator implements Communicator {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $communicatorInstance An instance of a Communicator class
+ */
+ public final static function create???NodeCommunicator () {
+ // Get new instance
+ $communicatorInstance = new ???NodeCommunicator();
+
+ // Return the prepared instance
+ return $communicatorInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general communicator class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 BaseCommunicator extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Init state which sets the state to 'init'
+ $this->initState();
+ }
+
+ /**
+ * Initializes the communicator's state which sets it to 'init'
+ *
+ * @return void
+ */
+ private function initState() {
+ // Get the state factory and create the initial state.
+ CommunicatorStateFactory::createCommunicatorStateInstanceByName('init', $this);
+ }
+
+ /**
+ * Initializes the executor, whatever it does.
+ *
+ * @return void
+ */
+ public function initExecutor (Stateable $stateInstance) {
+ $this->partialStub('Unfinished method with state ' . $this->getPrintableState() . '.');
+
+ // This communicator is now fully initialized so change the state
+ $stateInstance->communicatorHasInitialized();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A crawler->node communicator class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerNodeCommunicator extends BaseCommunicator implements Communicator, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $communicatorInstance An instance of a Communicator class
+ */
+ public final static function createCrawlerNodeCommunicator () {
+ // Get new instance
+ $communicatorInstance = new CrawlerNodeCommunicator();
+
+ // Return the prepared instance
+ return $communicatorInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A miner->node communicator class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 MinerNodeCommunicator extends BaseCommunicator implements Communicator, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $communicatorInstance An instance of a Communicator class
+ */
+ public final static function createMinerNodeCommunicator () {
+ // Get new instance
+ $communicatorInstance = new MinerNodeCommunicator();
+
+ // Return the prepared instance
+ return $communicatorInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A NetworkPackageCompressor decorator class. This decorator can later be
+ * easily extended without changing any other code.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NetworkPackageCompressorDecorator extends BaseHubSystem implements Compressor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $innerCompressorInstance The inner Compressor class
+ * @return $compressorInstance An instance of a Compressor class
+ */
+ public static final function createNetworkPackageCompressorDecorator (Compressor $innerCompressorInstance) {
+ // Get new instance
+ $compressorInstance = new NetworkPackageCompressorDecorator();
+
+ // Set the inner compressor class
+ $compressorInstance->setCompressorInstance($innerCompressorInstance);
+
+ // Return the prepared instance
+ return $compressorInstance;
+ }
+
+ /**
+ * A compression stream
+ *
+ * @param $streamData Mixed non-object stream data
+ * @return $streamData The compressed stream data
+ * @throws InvalidObjectException If the stream is an object
+ */
+ public function compressStream ($streamData) {
+ // Call the inner compressor class
+ return $this->getCompressorInstance()->compressStream($streamData);
+ }
+
+ /**
+ * A decompression stream
+ *
+ * @param $streamData Mixed non-object stream data
+ * @return $streamData The decompressed stream data
+ * @throws InvalidObjectException If the stream is an object
+ */
+ public function decompressStream ($streamData) {
+ // Call the inner compressor class
+ return $this->getCompressorInstance()->decompressStream($streamData);
+ }
+
+ /**
+ * Getter for the file extension of this compressor
+ *
+ * @return $string The compressor's file extension
+ */
+ public function getCompressorExtension () {
+ // Call the inner compressor class
+ return $this->getCompressorInstance()->getCompressorExtension();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A console controller for the apt-proxy program.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 HubConsoleAptProxyController extends BaseController implements Controller {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init additional filter chains
+ foreach (array('bootstrap','shutdown') as $filterChain) {
+ $this->initFilterChain($filterChain);
+ } // END - foreach
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $controllerInstance A prepared instance of this class
+ */
+ public static final function createHubConsoleAptProxyController (CommandResolver $resolverInstance) {
+ // Create the instance
+ $controllerInstance = new HubConsoleAptProxyController();
+
+ // Set the command resolver
+ $controllerInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $controllerInstance;
+ }
+
+ /**
+ * Handles the given request and response
+ *
+ * @param $requestInstance An instance of a request class
+ * @param $responseInstance An instance of a response class
+ * @return void
+ */
+ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the command instance from the resolver by sending a request instance to the resolver
+ $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+ // Add more filters by the command
+ $commandInstance->addExtraFilters($this, $requestInstance);
+
+ // Run the pre filters
+ $this->executePreFilters($requestInstance, $responseInstance);
+
+ // This request was valid! :-D
+ $requestInstance->requestIsValid();
+
+ // Execute the command
+ $commandInstance->execute($requestInstance, $responseInstance);
+
+ // Run the pre filters
+ $this->executePostFilters($requestInstance, $responseInstance);
+
+ // Flush the response out
+ $responseInstance->flushBuffer();
+ }
+
+ /**
+ * Add a bootstrap filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addBootstrapFilter (Filterable $filterInstance) {
+ $this->addFilter('bootstrap', $filterInstance);
+ }
+
+ /**
+ * Executes all bootstrap filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A console controller for the chat program.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 HubConsoleChatController extends BaseController implements Controller {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init additional filter chains
+ foreach (array('bootstrap','shutdown') as $filterChain) {
+ $this->initFilterChain($filterChain);
+ } // END - foreach
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $controllerInstance A prepared instance of this class
+ */
+ public static final function createHubConsoleChatController (CommandResolver $resolverInstance) {
+ // Create the instance
+ $controllerInstance = new HubConsoleChatController();
+
+ // Set the command resolver
+ $controllerInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $controllerInstance;
+ }
+
+ /**
+ * Handles the given request and response
+ *
+ * @param $requestInstance An instance of a request class
+ * @param $responseInstance An instance of a response class
+ * @return void
+ */
+ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the command instance from the resolver by sending a request instance to the resolver
+ $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+ // Add more filters by the command
+ $commandInstance->addExtraFilters($this, $requestInstance);
+
+ // Run the pre filters
+ $this->executePreFilters($requestInstance, $responseInstance);
+
+ // This request was valid! :-D
+ $requestInstance->requestIsValid();
+
+ // Execute the command
+ $commandInstance->execute($requestInstance, $responseInstance);
+
+ // Run the pre filters
+ $this->executePostFilters($requestInstance, $responseInstance);
+
+ // Flush the response out
+ $responseInstance->flushBuffer();
+ }
+
+ /**
+ * Add a bootstrap filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addBootstrapFilter (Filterable $filterInstance) {
+ $this->addFilter('bootstrap', $filterInstance);
+ }
+
+ /**
+ * Executes all bootstrap filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A console controller for the crawler program.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 HubConsoleCrawlerController extends BaseController implements Controller {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init additional filter chains
+ foreach (array('bootstrap','shutdown') as $filterChain) {
+ $this->initFilterChain($filterChain);
+ } // END - foreach
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $controllerInstance A prepared instance of this class
+ */
+ public static final function createHubConsoleCrawlerController (CommandResolver $resolverInstance) {
+ // Create the instance
+ $controllerInstance = new HubConsoleCrawlerController();
+
+ // Set the command resolver
+ $controllerInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $controllerInstance;
+ }
+
+ /**
+ * Handles the given request and response
+ *
+ * @param $requestInstance An instance of a request class
+ * @param $responseInstance An instance of a response class
+ * @return void
+ */
+ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the command instance from the resolver by sending a request instance to the resolver
+ $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+ // Add more filters by the command
+ $commandInstance->addExtraFilters($this, $requestInstance);
+
+ // Run the pre filters
+ $this->executePreFilters($requestInstance, $responseInstance);
+
+ // This request was valid! :-D
+ $requestInstance->requestIsValid();
+
+ // Execute the command
+ $commandInstance->execute($requestInstance, $responseInstance);
+
+ // Run the pre filters
+ $this->executePostFilters($requestInstance, $responseInstance);
+
+ // Flush the response out
+ $responseInstance->flushBuffer();
+ }
+
+ /**
+ * Add a bootstrap filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addBootstrapFilter (Filterable $filterInstance) {
+ $this->addFilter('bootstrap', $filterInstance);
+ }
+
+ /**
+ * Executes all bootstrap filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A console controller for the cruncher, which is our very first hub
+ * application.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 HubConsoleCruncherController extends BaseController implements Controller {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init additional filter chains
+ foreach (array('bootstrap','shutdown') as $filterChain) {
+ $this->initFilterChain($filterChain);
+ } // END - foreach
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $controllerInstance A prepared instance of this class
+ */
+ public static final function createHubConsoleCruncherController (CommandResolver $resolverInstance) {
+ // Create the instance
+ $controllerInstance = new HubConsoleCruncherController();
+
+ // Set the command resolver
+ $controllerInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $controllerInstance;
+ }
+
+ /**
+ * Handles the given request and response
+ *
+ * @param $requestInstance An instance of a request class
+ * @param $responseInstance An instance of a response class
+ * @return void
+ */
+ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the command instance from the resolver by sending a request instance to the resolver
+ $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+ // Add more filters by the command
+ $commandInstance->addExtraFilters($this, $requestInstance);
+
+ // Run the pre filters
+ $this->executePreFilters($requestInstance, $responseInstance);
+
+ // This request was valid! :-D
+ $requestInstance->requestIsValid();
+
+ // Execute the command
+ $commandInstance->execute($requestInstance, $responseInstance);
+
+ // Run the pre filters
+ $this->executePostFilters($requestInstance, $responseInstance);
+
+ // Flush the response out
+ $responseInstance->flushBuffer();
+ }
+
+ /**
+ * Add a bootstrap filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addBootstrapFilter (Filterable $filterInstance) {
+ $this->addFilter('bootstrap', $filterInstance);
+ }
+
+ /**
+ * Executes all bootstrap filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * The default controller with news for e.g. home or news page
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubConsoleDefaultNewsController extends BaseController implements Controller {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init additional filter chains
+ foreach (array('bootstrap', 'activation','shutdown') as $filterChain) {
+ $this->initFilterChain($filterChain);
+ } // END - foreach
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $controllerInstance A prepared instance of this class
+ */
+ public static final function createHubConsoleDefaultNewsController (CommandResolver $resolverInstance) {
+ // Create the instance
+ $controllerInstance = new HubConsoleDefaultNewsController();
+
+ // Set the command resolver
+ $controllerInstance->setResolverInstance($resolverInstance);
+
+ // Add news filters to this controller
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter'));
+ $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter'));
+
+ // Return the prepared instance
+ return $controllerInstance;
+ }
+
+ /**
+ * Handles the given request and response
+ *
+ * @param $requestInstance An instance of a request class
+ * @param $responseInstance An instance of a response class
+ * @return void
+ */
+ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the command instance from the resolver by sending a request instance to the resolver
+ $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+ // Add more filters by the command
+ $commandInstance->addExtraFilters($this, $requestInstance);
+
+ // Run the pre filters
+ $this->executePreFilters($requestInstance, $responseInstance);
+
+ // This request was valid! :-D
+ $requestInstance->requestIsValid();
+
+ // Execute the command
+ $commandInstance->execute($requestInstance, $responseInstance);
+
+ // Run the pre filters
+ $this->executePostFilters($requestInstance, $responseInstance);
+
+ // Flush the response out
+ $responseInstance->flushBuffer();
+ }
+
+ /**
+ * Add a bootstrap filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addBootstrapFilter (Filterable $filterInstance) {
+ $this->addFilter('bootstrap', $filterInstance);
+ }
+
+ /**
+ * Executes all bootstrap filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
+ }
+
+ /**
+ * Add a hub activation filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addActivationFilter (Filterable $filterInstance) {
+ $this->addFilter('activation', $filterInstance);
+ }
+
+ /**
+ * Executes all hub activation filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeActivationFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('activation', $requestInstance, $responseInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A console controller for the "continued hashing miner".
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Miner 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 HubConsoleMinerController extends BaseController implements Controller {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init additional filter chains
+ foreach (array('bootstrap','shutdown') as $filterChain) {
+ $this->initFilterChain($filterChain);
+ } // END - foreach
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $resolverInstance An instance of a command resolver class
+ * @return $controllerInstance A prepared instance of this class
+ */
+ public static final function createHubConsoleMinerController (CommandResolver $resolverInstance) {
+ // Create the instance
+ $controllerInstance = new HubConsoleMinerController();
+
+ // Set the command resolver
+ $controllerInstance->setResolverInstance($resolverInstance);
+
+ // Return the prepared instance
+ return $controllerInstance;
+ }
+
+ /**
+ * Handles the given request and response
+ *
+ * @param $requestInstance An instance of a request class
+ * @param $responseInstance An instance of a response class
+ * @return void
+ */
+ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get the command instance from the resolver by sending a request instance to the resolver
+ $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
+
+ // Add more filters by the command
+ $commandInstance->addExtraFilters($this, $requestInstance);
+
+ // Run the pre filters
+ $this->executePreFilters($requestInstance, $responseInstance);
+
+ // This request was valid! :-D
+ $requestInstance->requestIsValid();
+
+ // Execute the command
+ $commandInstance->execute($requestInstance, $responseInstance);
+
+ // Run the pre filters
+ $this->executePostFilters($requestInstance, $responseInstance);
+
+ // Flush the response out
+ $responseInstance->flushBuffer();
+ }
+
+ /**
+ * Add a bootstrap filter
+ *
+ * @param $filterInstance A Filterable class
+ * @return void
+ */
+ public function addBootstrapFilter (Filterable $filterInstance) {
+ $this->addFilter('bootstrap', $filterInstance);
+ }
+
+ /**
+ * Executes all bootstrap filters
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A node ??? crawler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Node???Crawler extends BaseNodeCrawler implements Crawler {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $crawlerInstance An instance of a Crawler class
+ */
+ public final static function createNode???Crawler () {
+ // Get new instance
+ $crawlerInstance = new Node???Crawler();
+
+ // Return the prepared instance
+ return $crawlerInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the crawler. This step does also apply provided
+ * command-line arguments stored in the request instance. You should now
+ * get it from calling $this->getRequestInstance().
+ *
+ * @return void
+ */
+ public function doBootstrapping () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Add some crawler-specific filters
+ *
+ * @param $controllerInstance An object of a Controller instance
+ * @param $responseInstance An object of a Responseable instance
+ * @return void
+ */
+ public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general NodeCrawler class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 BaseNodeCrawler extends BaseHubSystem {
+ /**
+ * Whether this Crawler is active
+ */
+ private $isActive = FALSE;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Set this crawler instance in registry
+ Registry::getRegistry()->addInstance('crawler', $this);
+
+ // Init state which sets the state to 'init'
+ $this->initState();
+ }
+
+ /**
+ * Initializes the node's state which sets it to 'init'
+ *
+ * @return void
+ */
+ private function initState() {
+ // Get the state factory and create the initial state.
+ CrawlerStateFactory::createCrawlerStateInstanceByName('init');
+ }
+
+ /**
+ * Initializes this crawler instance
+ *
+ * @param $stateInstance An instance of a Stateable class
+ * @return void
+ * @todo 0% done
+ */
+ public function initCrawler (Stateable $stateInstance) {
+ // Please implement
+ $this->partialStub('Unfinished method.');
+ }
+
+ /**
+ * Enables/disables the crawler (just sets a flag)
+ *
+ * @param $version Version number of this crawler
+ * @return void
+ */
+ public final function enableIsActive ($isActive = TRUE) {
+ $this->isActive = (bool) $isActive;
+ }
+
+ /**
+ * Determines whether the crawler is active
+ *
+ * @return $isActive Whether the crawler is active
+ */
+ public final function isActive () {
+ return $this->isActive;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A node console crawler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 NodeConsoleCrawler extends BaseNodeCrawler implements Crawler, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $crawlerInstance An instance of a Crawler class
+ */
+ public final static function createNodeConsoleCrawler () {
+ // Get new instance
+ $crawlerInstance = new NodeConsoleCrawler();
+
+ // Return the prepared instance
+ return $crawlerInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the crawler. This step does also apply provided
+ * command-line arguments stored in the request instance. You should now
+ * get it from calling $this->getRequestInstance().
+ *
+ * @return void
+ */
+ public function doBootstrapping () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ // Get the app instance (for shortening our code)
+ $app = $this->getApplicationInstance();
+
+ // Output all lines
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput('Distributed Crawler v' . $app->getAppVersion());
+ self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2014 Crawler Developer Team');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
+ self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
+ self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ }
+
+ /**
+ * Add some crawler-specific filters
+ *
+ * @param $controllerInstance An object of a Controller instance
+ * @param $responseInstance An object of a Responseable instance
+ * @return void
+ */
+ public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A hub-cruncher class for the '???' mode
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Cruncher Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Hub???Cruncher extends BaseHubCruncher implements CruncherHelper, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set version number
+ $this->setVersion('x.x');
+ }
+
+ /**
+ * Creates an instance of this hub-cruncher class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $cruncherInstance An instance of this hub-cruncher class
+ */
+ public final static function createHub???Cruncher (Requestable $requestInstance) {
+ // Get a new instance
+ $cruncherInstance = new Hub???Cruncher();
+
+ // Set the request instance
+ $cruncherInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $cruncherInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the cruncher. This step does also apply provided
+ * command-line arguments stored in the request instance. The regular cruncher
+ * should communicate with the bootstrap-crunchers at this point.
+ *
+ * @return void
+ * @todo Implement this method
+ */
+ public function doBootstrapping () {
+ // Call generic (parent) bootstrapping method first
+ parent::doGenericBootstrapping();
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Add some cruncher-specific filters
+ *
+ * @return void
+ */
+ public function addExtraHubFilters () {
+ // Add some filters here
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general hub cruncher class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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/>.
+ */
+abstract class BaseHubCruncher extends BaseHubSystem implements Updateable {
+ /**
+ * Version information
+ */
+ private $version = 'x.x';
+
+ /**
+ * By default no cruncher is active
+ */
+ private $isActive = FALSE;
+
+ /**
+ * All buffer queue instances (a FIFO)
+ */
+ private $bufferInstance = NULL;
+
+ /**
+ * Stacker name for incoming queue
+ */
+ const STACKER_NAME_IN_QUEUE = 'in_queue';
+
+ /**
+ * Stacker name for outcoming queue
+ */
+ const STACKER_NAME_OUT_QUEUE = 'out_queue';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Set this cruncher instance in registry
+ Registry::getRegistry()->addInstance('cruncher', $this);
+
+ // Init this cruncher
+ $this->initCruncher();
+ }
+
+ /**
+ * Initialize the cruncher generically
+ *
+ * @return void
+ */
+ private function initCruncher () {
+ // Init the state
+ CruncherStateFactory::createCruncherStateInstanceByName('init');
+ }
+
+ /**
+ * Getter for version
+ *
+ * @return $version Version number of this cruncher
+ */
+ protected final function getVersion () {
+ return $this->version;
+ }
+
+ /**
+ * Setter for version
+ *
+ * @param $version Version number of this cruncher
+ * @return void
+ */
+ protected final function setVersion ($version) {
+ $this->version = (string) $version;
+ }
+
+ /**
+ * Checks whether the in-buffer queue is filled by comparing it's current
+ * amount of entries against a threshold.
+ *
+ * @return $isFilled Whether the in-buffer is filled
+ */
+ protected function isInBufferQueueFilled () {
+ // Determine it
+ $isFilled = ($this->bufferInstance->getStackCount(self::STACKER_NAME_IN_QUEUE) > $this->getConfigInstance()->getConfigEntry('cruncher_in_buffer_min_threshold'));
+
+ // And return the result
+ return $isFilled;
+ }
+
+ /**
+ * This method fills the in-buffer with (a) test unit(s) which are mainly
+ * used for development of the crunching part. They must be enabled in
+ * configuration, or else your cruncher runs out of WUs and waits for more
+ * to show up.
+ *
+ * In this method we already know that the in-buffer is going depleted so
+ * no need to double-check it here.
+ *
+ * @return void
+ */
+ abstract protected function fillInBufferQueueWithTestUnits ();
+
+ /**
+ * This method fills the in-buffer with (real) WUs which will be crunched
+ * and the result be sent back to the key producer instance.
+ *
+ * @return void
+ */
+ abstract protected function fillInBufferQueueWithWorkUnits ();
+
+ /**
+ * Enables/disables the cruncher (just sets a flag)
+ *
+ * @param $version Version number of this cruncher
+ * @return void
+ */
+ public final function enableIsActive ($isActive = TRUE) {
+ $this->isActive = (bool) $isActive;
+ }
+
+ /**
+ * Determines whether the cruncher is active
+ *
+ * @return $isActive Whether the cruncher is active
+ */
+ public final function isActive () {
+ return $this->isActive;
+ }
+
+ /**
+ * Initializes all buffer queues (mostly in/out). This method is demanded
+ * by the CruncherHelper interface.
+ *
+ * @return void
+ */
+ public function initBufferQueues () {
+ /*
+ * Initialize both buffer queues, we can use the FIFO class here
+ * directly and encapsulate its method calls with protected methods.
+ */
+ $this->bufferInstance = ObjectFactory::createObjectByConfiguredName('cruncher_buffer_stacker_class');
+
+ // Initialize common stackers, like in/out
+ $this->bufferInstance->initStacks(array(
+ self::STACKER_NAME_IN_QUEUE,
+ self::STACKER_NAME_OUT_QUEUE
+ ));
+
+ // Output debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER: All buffers are now initialized.');
+ }
+
+ /**
+ * This method determines if the in-buffer is going to depleted and if so,
+ * it fetches more WUs from the network. If no WU can be fetched from the
+ * network and if enabled, a random test WU is being generated.
+ *
+ * This method is demanded from the CruncherHelper interface.
+ *
+ * @return void
+ */
+ public function doFetchWorkUnits () {
+ // Simply check if we have enough WUs left in the in-buffer queue (a FIFO)
+ if (!$this->isInBufferQueueFilled()) {
+ // The in-buffer queue needs filling, so head out and get some work
+ $this->fillInBufferQueueWithWorkUnits();
+
+ // Is the buffer still not filled and are test-packages allowed?
+ if ((!$this->isInBufferQueueFilled()) && ($this->getConfigInstance()->getConfigEntry('cruncher_test_units_enabled') == 'Y')) {
+ // Then fill the in-buffer with (one) test-unit(s)
+ $this->fillInBufferQueueWithTestUnits();
+ } // END - if
+ } // END - if
+ }
+
+ /**
+ * Updates a given field with new value
+ *
+ * @param $fieldName Field to update
+ * @param $fieldValue New value to store
+ * @return void
+ * @throws DatabaseUpdateSupportException If this class does not support database updates
+ * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
+ */
+ public function updateDatabaseField ($fieldName, $fieldValue) {
+ // Unfinished
+ $this->partialStub('Unfinished!');
+ return;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A hub-mcrypt cruncher class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 HubMcryptCruncher extends BaseHubCruncher implements CruncherHelper, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set version number
+ $this->setVersion('0.0.0');
+ }
+
+ /**
+ * Creates an instance of this hub-cruncher class
+ *
+ * @return $cruncherInstance An instance of this hub-cruncher class
+ */
+ public final static function createHubMcryptCruncher () {
+ // Get a new instance
+ $cruncherInstance = new HubMcryptCruncher();
+
+ // Return the instance
+ return $cruncherInstance;
+ }
+
+ /**
+ * This method fills the in-buffer with (a) test unit(s) which are mainly
+ * used for development of the crunching part. They must be enabled in
+ * configuration, or else your cruncher runs out of WUs and waits for more
+ * to show up.
+ *
+ * In this method we already know that the in-buffer is going depleted so
+ * no need to double-check it here.
+ *
+ * @return void
+ */
+ protected function fillInBufferQueueWithTestUnits () {
+ // Are test units enabled?
+ if ($this->getConfigInstance()->getConfigEntry('cruncher_test_units_enabled') == 'N') {
+ // They are disabled, so skip any further steps
+ return;
+ } elseif ($this->getStateInstance()->isCruncherStateVirgin()) {
+ // No virgin crunchers please, because they usually have no test units ready for crunching
+ return;
+ }
+
+ // Get a test-unit generator instance
+ $generatorInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_generator_class');
+
+ // We don't need an iterator here because we just need to generate some test units
+ for ($idx = 0; $idx < $this->getConfigInstance()->getConfigEntry('cruncher_max_text_unit_amount'); $idx++) {
+ // Get a test unit from it
+ $unitInstance = $generatorInstance->generateNextUnitInstance();
+
+ // ... and finally queue it to the in-buffer queue
+ $this->queueUnitInstanceToInBuffer($unitInstance);
+ } // END - for
+ }
+
+ /**
+ * This method fills the in-buffer with (real) WUs which will be crunched
+ * and the result be sent back to the key producer instance.
+ *
+ * @return void
+ */
+ protected function fillInBufferQueueWithWorkUnits () {
+ // This cruncher's state must not be one of these: 'virgin'
+ if ($this->getStateInstance()->isCruncherStateVirgin()) {
+ // We can silently skip here, until the generation is finished
+ return;
+ } // END - if
+
+ // @TODO Implement this method
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Method to "bootstrap" the cruncher. This step does also apply provided
+ * command-line arguments stored in the request instance. No buffer queue
+ * will be initialized here, we only do "general" things here.
+ *
+ * @return void
+ * @todo Implement this method
+ */
+ public function doBootstrapping () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ // Output all lines
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput('MCrypt Cruncher v' . $this->getVersion() . ' is starting ...');
+ self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2011 - 2014 Cruncher Developer Team');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
+ self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
+ self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ }
+
+ /**
+ * Add some cruncher-specific filters
+ *
+ * @param $controllerInstance An object of a Controller instance
+ * @param $responseInstance An object of a Responseable instance
+ * @return void
+ * @todo 0% done
+ */
+ public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
+ // Add some filters here
+ $this->partialStub('Please add some cruncher-specific filters, if required.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A database wrapper for cruncher work/test units
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherUnitDatabaseWrapper extends BaseDatabaseWrapper implements UnitDatabaseWrapper, Registerable {
+ // Constants for database table names
+ const DB_TABLE_CRUNCHER_UNITS = 'cruncher_units';
+
+ // Constants for database column names
+ const DB_COLUMN_UNIT_TYPE = 'unit_type';
+ const DB_COLUMN_UNIT_STATUS = 'unit_status';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this database wrapper by a provided user class
+ *
+ * @return $wrapperInstance An instance of the created wrapper class
+ */
+ public static final function createCruncherUnitDatabaseWrapper () {
+ // Get a new instance
+ $wrapperInstance = new CruncherUnitDatabaseWrapper();
+
+ // Set (primary!) table name
+ $wrapperInstance->setTableName(self::DB_TABLE_CRUNCHER_UNITS);
+
+ // Return the instance
+ return $wrapperInstance;
+ }
+
+ /**
+ * Checks whether a test unit has been produced
+ *
+ * @return $isProduced Whether a test unit has already been produced
+ */
+ public function isTestUnitProduced () {
+ // Now get a search instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Add criteria for looking up already created and available test units
+ $searchInstance->addCriteria(self::DB_COLUMN_UNIT_TYPE , BaseUnitProducer::UNIT_TYPE_TEST_UNIT);
+ $searchInstance->addCriteria(self::DB_COLUMN_UNIT_STATUS, BaseUnitProducer::UNIT_STATUS_AVAILABLE);
+ $searchInstance->setConfiguredLimit('cruncher_test_unit_max_count');
+
+ // Search for our units
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Do we have some entries?
+ $isProduced = $resultInstance->next();
+
+ // Return it
+ return $isProduced;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A database wrapper for distributed hash tables
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implements NodeDhtWrapper, Registerable {
+ /**
+ * "Cached" results for dabase for looking for unpublished entries
+ */
+ private $unpublishedEntriesInstance = NULL;
+
+ // Constants for database table names
+ const DB_TABLE_NODE_DHT = 'node_dht';
+
+ // Constants for database column names
+ const DB_COLUMN_NODE_ID = 'node_id';
+ const DB_COLUMN_SESSION_ID = 'session_id';
+ const DB_COLUMN_EXTERNAL_ADDRESS = 'external_address';
+ const DB_COLUMN_PRIVATE_KEY_HASH = 'private_key_hash';
+ const DB_COLUMN_NODE_MODE = 'node_mode';
+ const DB_COLUMN_ACCEPTED_OBJECTS = 'accepted_object_types';
+ const DB_COLUMN_NODE_LIST = 'node_list';
+ const DB_COLUMN_PUBLICATION_STATUS = 'publication_status';
+ const DB_COLUMN_ANSWER_STATUS = 'answer_status';
+ const DB_COLUMN_ACCEPT_BOOTSTRAP = 'accept_bootstrap';
+
+ // Publication status'
+ const PUBLICATION_STATUS_PENDING = 'PENDING';
+
+ // Exception codes
+ const EXCEPTION_NODE_ALREADY_REGISTERED = 0x800;
+ const EXCEPTION_NODE_NOT_REGISTERED = 0x801;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this database wrapper by a provided user class
+ *
+ * @return $wrapperInstance An instance of the created wrapper class
+ */
+ public static final function createNodeDistributedHashTableDatabaseWrapper () {
+ // Get a new instance
+ $wrapperInstance = new NodeDistributedHashTableDatabaseWrapper();
+
+ // Set (primary!) table name
+ $wrapperInstance->setTableName(self::DB_TABLE_NODE_DHT);
+
+ // Return the instance
+ return $wrapperInstance;
+ }
+
+ /**
+ * Static getter for an array of all DHT database entries
+ *
+ * @return $elements All elements for the DHT dabase
+ */
+ public static final function getAllElements () {
+ // Create array and ...
+ $elements = array(
+ self::DB_COLUMN_NODE_ID,
+ self::DB_COLUMN_SESSION_ID,
+ self::DB_COLUMN_EXTERNAL_ADDRESS,
+ self::DB_COLUMN_PRIVATE_KEY_HASH,
+ self::DB_COLUMN_NODE_MODE,
+ self::DB_COLUMN_ACCEPTED_OBJECTS,
+ self::DB_COLUMN_NODE_LIST
+ );
+
+ // ... return it
+ return $elements;
+ }
+
+ /**
+ * Prepares a search instance for given node data
+ *
+ * @param $nodeData An array with valid node data
+ * @return $searchInstance An instance of a SearchCriteria class
+ */
+ private function prepareSearchInstance (array $nodeData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Assert on array elements
+ assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
+
+ // Get instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for node id and limit it to one entry
+ $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]);
+ $searchInstance->setLimit(1);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+
+ // Return it
+ return $searchInstance;
+ }
+
+ /**
+ * Getter for result instance for unpublished entries
+ *
+ * @return $unpublishedEntriesInstance Result instance
+ */
+ public final function getUnpublishedEntriesInstance () {
+ return $this->unpublishedEntriesInstance;
+ }
+
+ /**
+ * Prepares a "local" instance of a StoreableCriteria class with all node
+ * data for insert/update queries. This data set contains data from *this*
+ * (local) node.
+ *
+ * @return $dataSetInstance An instance of a StoreableCriteria class
+ */
+ private function prepareLocalDataSetInstance () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Get node/request instances
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+ $requestInstance = ApplicationHelper::getSelfInstance()->getRequestInstance();
+
+ // Get a dataset instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
+
+ // Set the primary key
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
+
+ // Get Universal Node Locator and "explode" it
+ $unlInstance = $nodeInstance->determineUniversalNodeLocator();
+
+ // Get UNL data from it
+ $unlData = $unlInstance->getUnlData();
+
+ // Make sure both is valid
+ // @TODO Bad check on UNL, better use a proper validator
+ assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]));
+ assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] !== 'invalid');
+
+ // Get an array of all accepted object types
+ $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
+
+ // Make sure this is an array
+ assert(is_array($objectList));
+
+ // Add public node data
+ $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE , $requestInstance->getRequestElement('mode'));
+ $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
+ $dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getPrivateKeyHash());
+ $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
+ $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPT_BOOTSTRAP, $this->translateBooleanToYesNo($nodeInstance->isAcceptingDhtBootstrap()));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+
+ // Return it
+ return $dataSetInstance;
+ }
+
+ /**
+ * Checks whether the local (*this*) node is registered in the DHT by
+ * checking if the external address is found.
+ *
+ * @return $isRegistered Whether *this* node is registered in the DHT
+ */
+ public function isLocalNodeRegistered () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Get a search criteria instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Get Universal Node Locator and "explode" it
+ $unlData = $nodeInstance->getUniversalNodeLocatorArray();
+
+ // Make sure the external address is set and not invalid
+ // @TODO Bad check on UNL, better use a proper validator
+ assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]));
+ assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] != 'invalid');
+
+ // Add Universal Node Locator/node id as criteria
+ $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]);
+ $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
+ $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
+ $searchInstance->setLimit(1);
+
+ // Query database and get a result instance back
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Cache result of if there is an entry, valid() will tell us if an entry is there
+ $isRegistered = $resultInstance->valid();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
+
+ // Return result
+ return $isRegistered;
+ }
+
+ /**
+ * Registeres the local (*this*) node with its data in the DHT.
+ *
+ * @return void
+ */
+ public function registerLocalNode () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Assert to make sure this method is called with no record in DB (the actual backend of the DHT)
+ assert(!$this->isLocalNodeRegistered());
+
+ // Get prepared data set instance
+ $dataSetInstance = $this->prepareLocalDataSetInstance();
+
+ // "Insert" this dataset instance completely into the database
+ $this->queryInsertDataSet($dataSetInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Updates local (*this*) node's data in DHT, this is but not limited to the
+ * session id, ip number (and/or hostname) and port number.
+ *
+ * @return void
+ */
+ public function updateLocalNode () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Assert to make sure this method is called with one record in DB (the actual backend of the DHT)
+ assert($this->isLocalNodeRegistered());
+
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Get search criteria
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for node id and limit it to one entry
+ $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeInstance->getNodeId());
+ $searchInstance->setLimit(1);
+
+ // Get a prepared dataset instance
+ $dataSetInstance = $this->prepareLocalDataSetInstance();
+
+ // Set search instance
+ $dataSetInstance->setSearchInstance($searchInstance);
+
+ // Update DHT database record
+ $this->queryUpdateDataSet($dataSetInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Finds a node locally by given session id
+ *
+ * @param $sessionId Session id to lookup
+ * @return $nodeData Node data array
+ */
+ public function findNodeLocalBySessionId ($sessionId) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ' - CALLED!');
+
+ // Get search criteria
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for session id and limit it to one entry
+ $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID, $sessionId);
+ $searchInstance->setLimit(1);
+
+ // Query database and get a result instance back
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!');
+
+ // Return result instance
+ return $resultInstance;
+ }
+
+ /**
+ * Registeres a node by given message data.
+ *
+ * @param $messageData An array of all message data
+ * @param $handlerInstance An instance of a HandleableDataSet class
+ * @return void
+ */
+ public function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: handlerInstance=' . $handlerInstance->__toString() . ' - CALLED!');
+
+ // Get a data set instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
+
+ // Set primary key (session id)
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
+
+ // Add all array elements
+ $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Remove 'node_list'
+ $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
+
+ // Run the "INSERT" query
+ $this->queryInsertDataSet($dataSetInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . '] - EXIT!');
+ }
+
+ /**
+ * Updates an existing entry in node list
+ *
+ * @param $messageData An array of all message data
+ * @param $handlerInstance An instance of a HandleableDataSet class
+ * @param $searchInstance An instance of LocalSearchCriteria class
+ * @return void
+ */
+ public function updateNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Get a data set instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
+
+ // Add search instance
+ $dataSetInstance->setSearchInstance($searchInstance);
+
+ // Set primary key (session id)
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
+
+ // Add all array elements
+ $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Remove 'node_list'
+ $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
+
+ // Run the "UPDATE" query
+ $this->queryUpdateDataSet($dataSetInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Determines whether the given node data is already inserted in the DHT
+ *
+ * @param $nodeData An array with valid node data
+ * @return $isRegistered Whether the given node data is already inserted
+ */
+ public function isNodeRegistered (array $nodeData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Assert on array elements
+ assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]);
+
+ // Get search criteria
+ $searchInstance = $this->prepareSearchInstance($nodeData);
+
+ // Query database and get a result instance back
+ $resultInstance = $this->doSelectByCriteria(
+ // Search instance
+ $searchInstance,
+ // Only look for these array elements ("keys")
+ array(
+ self::DB_COLUMN_NODE_ID => TRUE,
+ self::DB_COLUMN_EXTERNAL_ADDRESS => TRUE
+ )
+ );
+
+ // Check if there is an entry
+ $isRegistered = $resultInstance->valid();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
+
+ // Return registration status
+ return $isRegistered;
+ }
+
+ /**
+ * Registers a node with given data in the DHT. If the node is already
+ * registered this method shall throw an exception.
+ *
+ * @param $nodeData An array with valid node data
+ * @return void
+ * @throws NodeAlreadyRegisteredException If the node is already registered
+ */
+ public function registerNode (array $nodeData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Assert on array elements
+ assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
+
+ // Is the node registered?
+ if ($this->isNodeRegistered($nodeData)) {
+ // Throw an exception
+ throw new NodeAlreadyRegisteredException(array($this, $nodeData), self::EXCEPTION_NODE_ALREADY_REGISTERED);
+ } // END - if
+
+ // @TODO Unimplemented part
+ $this->partialStub('nodeData=' . print_r($nodeData, TRUE));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Updates a node's entry in the DHT with given data. This will enrich or
+ * just update already exsiting data. If the node is not found this method
+ * shall throw an exception.
+ *
+ * @param $nodeData An array with valid node data
+ * @return void
+ * @throws NodeDataMissingException If the node's data is missing
+ */
+ public function updateNode (array $nodeData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Assert on array elements
+ assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...');
+
+ // Is the node registered?
+ if (!$this->isNodeRegistered($nodeData)) {
+ // No, then throw an exception
+ throw new NodeDataMissingException(array($this, $nodeData), self::EXCEPTION_NODE_NOT_REGISTERED);
+ } // END - if
+
+ // Get a search instance
+ $searchInstance = $this->prepareSearchInstance($nodeData);
+
+ // Get a data set instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
+
+ // Add search instance
+ $dataSetInstance->setSearchInstance($searchInstance);
+
+ // Set primary key (session id)
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
+
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: nodeData=' . print_r($nodeData, TRUE));
+
+ // Add all array elements
+ $nodeInstance->addArrayToDataSet($dataSetInstance, $nodeData);
+
+ // Remove 'node_list'
+ $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
+
+ // Run the "UPDATE" query
+ $this->queryUpdateDataSet($dataSetInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Checks whether there are unpublished entries
+ *
+ * @return $hasUnpublished Whether there are unpublished entries
+ * @todo Add minimum/maximum age limitations
+ */
+ public function hasUnpublishedEntries () {
+ // Get search instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Add exclusion key which is the publish status
+ $searchInstance->addExcludeCriteria(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PUBLICATION_STATUS, NodeDistributedHashTableDatabaseWrapper::PUBLICATION_STATUS_PENDING);
+
+ // Remember search instance
+ $this->setSearchInstance($searchInstance);
+
+ // Run the query
+ $this->unpublishedEntriesInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Check pending entries
+ $hasUnpublished = $this->unpublishedEntriesInstance->valid();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+
+ // Return it
+ return $hasUnpublished;
+ }
+
+ /**
+ * Initializes publication of DHT entries. This does only prepare
+ * publication. The next step is to pickup such prepared entries and publish
+ * them by uploading to other (recently appeared) DHT members.
+ *
+ * @return void
+ * @todo Add timestamp to dataset instance
+ */
+ public function initEntryPublication () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ /*
+ * Make sure that hasUnpublishedEntries() has been called first by
+ * asserting on the "cached" object instance. This "caching" saves some
+ * needless queries as this method shall be called immediately after
+ * hasUnpublishedEntries() returns TRUE.
+ */
+ assert($this->unpublishedEntriesInstance instanceof SearchableResult);
+
+ // Result is still okay?
+ assert($this->unpublishedEntriesInstance->valid());
+
+ // Remove 'publication_status'
+ $this->getSearchInstance()->unsetCriteria(self::DB_COLUMN_PUBLICATION_STATUS);
+
+ // Make sure all entries are marked as pending, first get a dataset instance.
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
+
+ // Add search instance
+ $dataSetInstance->setSearchInstance($this->getSearchInstance());
+
+ // Set primary key (node id)
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
+
+ // Add criteria (that should be set)
+ $dataSetInstance->addCriteria(self::DB_COLUMN_PUBLICATION_STATUS, self::PUBLICATION_STATUS_PENDING);
+
+ // Run the "UPDATE" query
+ $this->queryUpdateDataSet($dataSetInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Removes non-public data from given array.
+ *
+ * @param $data An array with possible non-public data that needs to be removed.
+ * @return $data A cleaned up array with only public data.
+ */
+ public function removeNonPublicDataFromArray(array $data) {
+ // Currently call only inner method
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...');
+ $data = parent::removeNonPublicDataFromArray($data);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: data[]=' . gettype($data));
+
+ // Return cleaned data
+ return $data;
+ }
+
+ /**
+ * Find recipients for given package data and exclude the sender
+ *
+ * @param $packageData An array of valid package data
+ * @return $recipients An indexed array with DHT recipients
+ */
+ public function getResultFromExcludedSender (array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Assert on required array field
+ assert(isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER]));
+
+ // Get max recipients
+ $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
+
+ // First creata a search instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Then exclude 'sender' field as the sender is the current (*this*) node
+ $searchInstance->addExcludeCriteria(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
+
+ // Set limit to maximum DHT recipients
+ $searchInstance->setLimit($maxRecipients);
+
+ // Get a result instance back from DHT database wrapper.
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+
+ // Return result instance
+ return $resultInstance;
+ }
+
+ /**
+ * Find recopients by given key/value pair. First look for the key and if it
+ * matches, compare the value.
+ *
+ * @param $key Key to look for
+ * @param $value Value to compare if key matches
+ * @return $recipients An indexed array with DHT recipients
+ */
+ public function getResultFromKeyValue ($key, $value) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Get max recipients
+ $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
+
+ // First creata a search instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Find the key/value pair
+ $searchInstance->addCriteria($key, $value);
+
+ // Get a result instance back from DHT database wrapper.
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+
+ // Return result instance
+ return $resultInstance;
+ }
+
+ /**
+ * Enable DHT bootstrap request acceptance for local node
+ *
+ * @return void
+ */
+ public function enableAcceptDhtBootstrap () {
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...');
+
+ // Is the node already registered?
+ if ($this->isLocalNodeRegistered()) {
+ // Just update our record
+ $this->updateLocalNode();
+ } else {
+ // Register it
+ $this->registerLocalNode();
+ }
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A database wrapper for node informations
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeInformationDatabaseWrapper extends BaseDatabaseWrapper implements NodeInformationWrapper, Registerable {
+ // Constants for database table names
+ const DB_TABLE_NODE_INFORMATION = 'node_data';
+
+ // Constants for database column names
+ const DB_COLUMN_NODE_NR = 'node_nr';
+ const DB_COLUMN_NODE_ID = 'node_id';
+ const DB_COLUMN_SESSION_ID = 'session_id';
+ const DB_COLUMN_PRIVATE_KEY = 'private_key';
+ const DB_COLUMN_PRIVATE_KEY_HASH = 'private_key_hash';
+ const DB_COLUMN_NODE_MODE = 'node_mode';
+ const DB_COLUMN_INTERNAL_UNL = 'internal_unl';
+ const DB_COLUMN_EXTERNAL_UNL = 'external_unl';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this database wrapper by a provided user class
+ *
+ * @return $wrapperInstance An instance of the created wrapper class
+ */
+ public static final function createNodeInformationDatabaseWrapper () {
+ // Get a new instance
+ $wrapperInstance = new NodeInformationDatabaseWrapper();
+
+ // Set (primary!) table name
+ $wrapperInstance->setTableName(self::DB_TABLE_NODE_INFORMATION);
+
+ // Return the instance
+ return $wrapperInstance;
+ }
+
+ /**
+ * Checks whether there is an entry for given node instance
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return $isFound Whether a node id has been found for this node
+ */
+ public function ifNodeDataIsFound (NodeHelper $nodeInstance) {
+ // Is there cache?
+ if (!isset($GLOBALS[__METHOD__])) {
+ // Now get a search criteria instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for the node number one which is hard-coded the default
+ $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
+ $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $nodeInstance->getRequestInstance()->getRequestElement('mode'));
+ $searchInstance->setLimit(1);
+
+ // Get a result back
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Set result instance in node instance
+ $nodeInstance->setResultInstance($resultInstance);
+
+ // Is it valid?
+ $GLOBALS[__METHOD__] = $resultInstance->next();
+ } // END - if
+
+ // Return it
+ return $GLOBALS[__METHOD__];
+ }
+
+ /**
+ * 'Registers' a new node id along with data provided in the node instance.
+ * This may sound confusing but avoids double code very nicely...
+ *
+ * @param $nodeInstance A node instance
+ * @param $requestInstance An instance of a Requestable class
+ * @return void
+ */
+ public function registerNodeId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
+ // Get a dataset instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
+
+ // Set the primary key
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
+
+ // Add registration elements to the dataset
+ $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
+
+ // "Insert" this dataset instance completely into the database
+ $this->queryInsertDataSet($dataSetInstance);
+ }
+
+ /**
+ * 'Registers' a new session id along with data provided in the node instance.
+ * This may sound confusing but avoids double code very nicely...
+ *
+ * @param $nodeInstance An instance of a BaseHubNode class
+ * @param $requestInstance An instance of a Requestable class
+ * @param $searchInstance An instance of a LocalSearchCriteria class
+ * @return void
+ */
+ public function registerSessionId (BaseHubNode $nodeInstance, Requestable $requestInstance, LocalSearchCriteria $searchInstance) {
+ // Get a dataset instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
+
+ // Set search instance
+ $dataSetInstance->setSearchInstance($searchInstance);
+
+ // Set the primary key
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
+
+ // Add registration elements to the dataset
+ $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
+
+ // Update database record
+ $this->queryUpdateDataSet($dataSetInstance);
+ }
+
+ /**
+ * 'Registers' a private key along with data provided in the node instance.
+ * This may sound confusing but avoids double code very nicely...
+ *
+ * @param $nodeInstance An instance of a BaseHubNode class
+ * @param $requestInstance An instance of a Requestable class
+ * @param $searchInstance An instance of a LocalSearchCriteria class
+ * @return void
+ */
+ public function registerPrivateKey (BaseHubNode $nodeInstance, Requestable $requestInstance, LocalSearchCriteria $searchInstance) {
+ // Get a dataset instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
+
+ // Set the primary key
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
+
+ // Set search instance
+ $dataSetInstance->setSearchInstance($searchInstance);
+
+ // Add registration elements to the dataset
+ $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
+
+ // Update database record
+ $this->queryUpdateDataSet($dataSetInstance);
+ }
+
+ /**
+ * Removes non-public data from given array.
+ *
+ * @param $data An array with possible non-public data that needs to be removed.
+ * @return $data A cleaned up array with only public data.
+ */
+ public function removeNonPublicDataFromArray(array $data) {
+ // Currently call only inner method
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...');
+ $data = parent::removeNonPublicDataFromArray($data);
+
+ // Return cleaned data
+ return $data;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A database wrapper for peer state lookups
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements LookupablePeerState {
+ // Exception constants
+ const EXCEPTION_PEER_ALREADY_REGISTERED = 0x300;
+
+ // Constants for database table names
+ const DB_TABLE_PEER_LOOKUP = 'peer_states';
+
+ // Constants for database column names
+ const DB_COLUMN_PEER_IP = 'peer_ip';
+ const DB_COLUMN_PEER_PORT = 'peer_port';
+ const DB_COLUMN_PEER_SESSION_ID = 'peer_session_id';
+ const DB_COLUMN_PEER_STATE = 'peer_state';
+ const DB_COLUMN_SOCKET_ERROR_CODE = 'socket_error_code';
+ const DB_COLUMN_SOCKET_ERROR_MSG = 'socket_error_msg';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this database wrapper by a provided user class
+ *
+ * @return $wrapperInstance An instance of the created wrapper class
+ */
+ public static final function createPeerStateLookupDatabaseWrapper () {
+ // Get a new instance
+ $wrapperInstance = new PeerStateLookupDatabaseWrapper();
+
+ // Set (primary!) table name
+ $wrapperInstance->setTableName(self::DB_TABLE_PEER_LOOKUP);
+
+ // Return the instance
+ return $wrapperInstance;
+ }
+
+ /**
+ * "Getter" for a LocalSearchCriteria from given package data's sender
+ *
+ * @param $packageData Valid raw package data array
+ * @return $searchInstance An instance of a LocalSearchCriteria class
+ */
+ private function getSenderSearchInstanceFromPackageData (array $packageData) {
+ // Get the instance
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: Searching for sender ' . $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Add 'sender' as the peer's IP address
+ $searchInstance->addCriteria(self::DB_COLUMN_PEER_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
+ $searchInstance->setLimit(1);
+
+ // Return the instance
+ return $searchInstance;
+ }
+
+ /**
+ * Checks whether given 'sender' is a new peer
+ *
+ * @param $packageData Raw package data
+ * @param $dataSetInstance An optional instance of a StoreableCriteria class
+ * @return $isNewPeer Whether 'sender' is a new peer to this peer
+ */
+ public function isSenderNewPeer (array $packageData, StoreableCriteria $dataSetInstance = NULL) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: ' . __FUNCTION__ . ' called with packageData()=' . count($packageData) . ' - CALLED!');
+
+ // Is the package valid?
+ if (!isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER])) {
+ // Invalid package found, please report this
+ $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE));
+ } // END - if
+
+ // Get a search criteria instance from package data
+ $searchInstance = $this->getSenderSearchInstanceFromPackageData($packageData);
+
+ // Is the dataset instance set?
+ if ($dataSetInstance instanceof StoreableCriteria) {
+ // Then remember the search instance in it
+ $dataSetInstance->setSearchInstance($searchInstance);
+ } // END - if
+
+ // Count the query
+ $entries = $this->doSelectCountByCriteria($searchInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE));
+
+ // Is it there?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: entries=' . $entries);
+ $isNewPeer = ($entries != 1);
+
+ // Return the result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: isNewPeer=' . intval($isNewPeer) . ' - EXIT!');
+ return $isNewPeer;
+ }
+
+ /**
+ * Registers a new peer with given package data. We use the session id from it.
+ *
+ * @param $packageData Raw package data
+ * @param $socketResource A valid socket resource
+ * @return void
+ * @throws PeerAlreadyRegisteredException If a peer is already registered
+ */
+ public function registerPeerByPackageData (array $packageData, $socketResource) {
+ // Make sure only new peers can be registered with package data
+ if (!$this->isSenderNewPeer($packageData)) {
+ // Throw an exception because this should normally not happen
+ throw new PeerAlreadyRegisteredException(array($this, $packageData), self::EXCEPTION_PEER_ALREADY_REGISTERED);
+ } // END - if
+
+ // Generate a dataset instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_PEER_LOOKUP));
+
+ // Session ids must be unique
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_PEER_SESSION_ID);
+
+ // Add session id
+ $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
+
+ // Get peer name
+ if (!@socket_getpeername($socketResource, $peerName, $peerPort)) {
+ // Get last error
+ $lastError = socket_last_error($socketResource);
+
+ // ... and cleartext message from it and put both into criteria
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_CODE, $lastError);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_MSG , socket_strerror($lastError));
+ } // END - if
+
+ // Add ip address and port
+ $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_IP , $peerName);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_PORT, $peerPort);
+
+ // "Insert" the data set
+ $this->queryInsertDataSet($dataSetInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: Peer ' . $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . ' has been registered.');
+ }
+
+ /**
+ * Registers the given peer state and raw package data
+ *
+ * @param $stateInstance A PeerStateable class instance
+ * @param $packageData Valid package data array
+ * @return void
+ * @throws PeerAlreadyRegisteredException If a peer is already registered
+ * @todo Unfinished area
+ */
+ public function registerPeerState (PeerStateable $stateInstance, array $packageData) {
+ // Generate a dataset instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_PEER_LOOKUP));
+
+ // Session ids must be unique
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_PEER_SESSION_ID);
+
+ // Add session id
+ $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_STATE , $stateInstance->getStateName());
+
+ // Try to resolve sender's session id
+ $senderData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_SENDER]));
+
+ // Just make sure that 'invalid:invalid' is not being processed
+ assert(($senderData[0] != 'invalid') && ($senderData[1] != 'invalid') && ($senderData[2] != 'invalid'));
+
+ // Add ip address and port
+ $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_IP , $senderData[0]);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_PORT, $senderData[1]);
+
+ // Is this a new peer?
+ if ($this->isSenderNewPeer($packageData, $dataSetInstance)) {
+ // "Insert" the data set
+ $this->queryInsertDataSet($dataSetInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE));
+ } else {
+ // Update the data set
+ $this->queryUpdateDataSet($dataSetInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE));
+ }
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: Peer ' . $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . ' has been registered/updated with state ' . $stateInstance->getStateName());
+ }
+
+ /**
+ * Purges old entries of given socket resource. We use the IP address from that resource.
+ *
+ * @param $socketResource A valid socket resource
+ * @return void
+ * @throws InvalidSocketException If the socket resource was invalid
+ * @todo Unfinished area
+ */
+ public function purgeOldEntriesBySocketResource ($socketResource) {
+ // Get peer name
+ if (!@socket_getpeername($socketResource, $peerName, $peerPort)) {
+ // Get last error
+ $lastError = socket_last_error($socketResource);
+
+ // Doesn't work!
+ throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: peerName=' . $peerName . ',peerPort=' . $peerPort . ' - UNFINISHED!');
+ }
+
+ /**
+ * 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 Valid package data array
+ * @return $isSamePeerState Whether the peer's state is the same
+ */
+ public function isSamePeerState (ConnectionHelper $helperInstance, array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: State ' . $helperInstance->getPrintableState() . ' needs to be checked it has changed ...');
+
+ // Now get the search instance from given package data
+ $searchInstance = $this->getSenderSearchInstanceFromPackageData($packageData);
+
+ // With this search instance query the database for the peer and get a result instance
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Do we have an entry? This should always the case
+ assert($resultInstance->next());
+
+ // Yes, so get the current (=first) entry from it
+ $rowData = $resultInstance->current();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: rowData[' . gettype($rowData) . ']=' . print_r($rowData, TRUE));
+
+ // Assert on important elements
+ assert(isset($rowData[self::DB_COLUMN_PEER_STATE]));
+
+ // Now just compare it with given state from helper instance
+ $isSamePeerState = ($rowData[self::DB_COLUMN_PEER_STATE] == $helperInstance->getPrintableState());
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: state in database: ' . $rowData[self::DB_COLUMN_PEER_STATE] . ', new state: ' . $helperInstance->getPrintableState() . ',isSamePeerState=' . intval($isSamePeerState));
+
+ // Return it
+ return $isSamePeerState;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? decoder class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Decoder extends BaseDecoder implements Decodeable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $decoderInstance An instance of a Decodeable class
+ */
+ public final static function create???Decoder () {
+ // Get new instance
+ $decoderInstance = new ???Decoder();
+
+ // Return the prepared instance
+ return $decoderInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Decoder class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseDecoder extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Package decoder class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageDecoder extends BaseDecoder implements Decodeable, Registerable {
+ /**
+ * Name for stacker for received packages
+ */
+ const STACKER_NAME_DECODED_PACKAGE = 'decoded_package';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $handlerInstance An instance of a HandleableChunks class
+ * @return $decoderInstance An instance of a Decodeable class
+ */
+ public final static function createPackageDecoder (HandleableChunks $handlerInstance) {
+ // Get new instance
+ $decoderInstance = new PackageDecoder();
+
+ // Init stacker for received packages
+ $handlerInstance->getStackInstance()->initStack(self::STACKER_NAME_DECODED_PACKAGE);
+
+ // Set the handler instance here
+ $decoderInstance->setHandlerInstance($handlerInstance);
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // And set it in this decoder
+ $decoderInstance->setPackageInstance($packageInstance);
+
+ // Return the prepared instance
+ return $decoderInstance;
+ }
+
+ /**
+ * Checks whether the assoziated stacker for raw package data has some entries left
+ *
+ * @return $unhandledDataLeft Whether some unhandled raw package data is left
+ */
+ public function ifUnhandledRawPackageDataLeft () {
+ // Check it
+ $unhandledDataLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA));
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: unhandledDataLeft=' . intval($unhandledDataLeft));
+ return $unhandledDataLeft;
+ }
+
+ /**
+ * Handles raw package data by decoding it
+ *
+ * @return void
+ */
+ public function handleRawPackageData () {
+ // Assert on it to make sure the next popNamed() call won't throw an exception
+ assert($this->ifUnhandledRawPackageDataLeft());
+
+ // "Pop" the next raw package content
+ $rawPackageContent = $this->getHandlerInstance()->getStackInstance()->popNamed(ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: Got ' . strlen($rawPackageContent) . ' bytes from stack ' . ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA . ', decoding it ...');
+
+ // "Decode" the raw package content by using the NetworkPackage instance
+ $decodedData = $this->getPackageInstance()->decodeRawContent($rawPackageContent);
+
+ // Some checks
+ assert(
+ (is_array($decodedData)) &&
+ (isset($decodedData[NetworkPackage::PACKAGE_DATA_SENDER])) &&
+ (isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) &&
+ (isset($decodedData[NetworkPackage::PACKAGE_DATA_CONTENT])) &&
+ (isset($decodedData[NetworkPackage::PACKAGE_DATA_STATUS]))
+ );
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: decodedData(' . count($decodedData) . ')=' . print_r($decodedData, TRUE));
+
+ // Next get a recipient-discovery instance
+ $discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
+
+ // ... then disover all recipient (might be only one), this package may shall be forwarded
+ $discoveryInstance->discoverRawRecipients($decodedData);
+
+ // Check for 'recipient' field (the 'sender' field and others are ignored here)
+ if ($discoveryInstance->isRecipientListEmpty()) {
+ // The recipient is this node so next stack it on 'decoded_package'
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: Pushing ' . strlen($decodedData) . ' bytes to stack ' . self::STACKER_NAME_DECODED_PACKAGE . ' ...');
+ $this->getHandlerInstance()->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_PACKAGE, $decodedData);
+ } else {
+ // Forward the package to the next node
+ $this->getPackageInstance()->forwardRawPackage($decodedData);
+ }
+ }
+
+ /**
+ * Checks whether decoded packages have arrived (for this peer)
+ *
+ * @return $ifRawPackagesLeft Whether decoded packages have arrived
+ */
+ public function ifDeocedPackagesLeft () {
+ // Check it ...
+ $ifRawPackagesLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_PACKAGE));
+
+ // ... return it
+ return $ifRawPackagesLeft;
+ }
+
+ /**
+ * Handles received decoded packages internally (recipient is this node)
+ *
+ * @return void
+ */
+ public function handleDecodedPackage () {
+ // Assert on amount
+ assert($this->ifDeocedPackagesLeft());
+
+ // Get the next entry (assoziative array)
+ $decodedData = $this->getHandlerInstance()->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_PACKAGE);
+
+ // Handle it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: decodedData(' . count($decodedData) . ')=' . print_r($decodedData, TRUE));
+ $this->getPackageInstance()->handleRawData($decodedData);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? DHT facade class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???DhtFacade extends BaseDht implements Distributable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $dhtInstance An instance of a Distributable class
+ */
+ public final static function create??? () {
+ // Get new instance
+ $dhtInstance = new ???DhtFacade();
+
+ // Return the prepared instance
+ return $dhtInstance;
+ }
+
+ /**
+ * Registers/updates an entry in the DHT with given data from $dhtData
+ * array. Different DHT implemtations may handle this differently as they
+ * may enrich the data with more meta data.
+ *
+ * @param $dhtData A valid array with DHT-related data (e.g. node/peer data)
+ * @return void
+ * @todo 0% done
+ */
+ protected function insertDataIntoDht (array $dhtData) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general DHT class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
+ */
+abstract class BaseDht extends BaseHubSystem implements Distributable {
+ /**
+ * "Cached" instance of a publish helper
+ */
+ private $publishHelperInstance = NULL;
+
+ /**
+ * Stacker name for "INSERT" node data
+ */
+ const STACKER_NAME_INSERT_NODE = 'dht_insert_node';
+ const STACKER_NAME_PENDING_PUBLISHING = 'dht_pending_publish';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Get a stacker instance for this DHT
+ $stackInstance = ObjectFactory::createObjectByConfiguredName('dht_stacker_class');
+
+ // Set it in this class
+ $this->setStackInstance($stackInstance);
+
+ // Init all stackers
+ $this->initStacks();
+
+ // Get the state factory and create the initial state.
+ DhtStateFactory::createDhtStateInstanceByName('init', $this);
+ }
+
+ /**
+ * Initializes all stackers
+ *
+ * @return void
+ */
+ private function initStacks () {
+ // Initialize all stacker
+ $this->getStackInstance()->initStacks(array(
+ self::STACKER_NAME_INSERT_NODE,
+ self::STACKER_NAME_PENDING_PUBLISHING,
+ ));
+ }
+
+ /**
+ * Registers/updates an entry in the DHT with given data from $dhtData
+ * array. Different DHT implemtations may handle this differently as they
+ * may enrich the data with more meta data.
+ *
+ * @param $dhtData A valid array with DHT-related data (e.g. node/peer data)
+ * @return void
+ */
+ protected abstract function insertDataIntoDht (array $dhtData);
+
+ /**
+ * Updates/refreshes DHT data (e.g. status).
+ *
+ * @return void
+ * @todo Find more to do here
+ */
+ public function updateDhtData () {
+ // Set some dummy configuration entries, e.g. dht_status
+ $this->getConfigInstance()->setConfigEntry('dht_status', $this->getStateInstance()->getStateName());
+ }
+
+ /**
+ * Checks whether there are entries in "INSERT" node data stack
+ *
+ * @return $isPending Whether there are pending entries
+ */
+ public function ifInsertNodeDataPending () {
+ // Determine it if it is not empty
+ $isPending = ($this->getStackInstance()->isStackEmpty(self::STACKER_NAME_INSERT_NODE) === FALSE);
+
+ // Return status
+ return $isPending;
+ }
+
+ /**
+ * Inserts a single entry of node data into the DHT
+ *
+ * @return void
+ */
+ public function insertSingleNodeData () {
+ // Get next node data from stack
+ $nodeData = $this->getStackInstance()->popNamed(self::STACKER_NAME_INSERT_NODE);
+
+ // Make sure $nodeData is really an array and has at least one entry
+ assert((is_array($nodeData)) && (count($nodeData) > 0));
+
+ // Insert the data
+ $this->insertDataIntoDht($nodeData);
+ }
+
+ /**
+ * Checks whether there are unpublished entries
+ *
+ * @return $hasUnpublished Whether there are unpublished entries
+ * @todo Add minimum/maximum age limitations
+ */
+ public function hasUnpublishedEntries () {
+ // Call method on database wrapper
+ $hasUnpublished = $this->getWrapperInstance()->hasUnpublishedEntries();
+
+ // Return it
+ return $hasUnpublished;
+ }
+
+ /**
+ * Initializes publication of DHT entries. This does only prepare
+ * publication. The next step is to pickup such prepared entries and publish
+ * them by uploading to other (recently appeared) DHT members.
+ *
+ * @return void
+ */
+ public function initEntryPublication () {
+ // Call method on database wrapper
+ $this->getWrapperInstance()->initEntryPublication();
+
+ // Get result instance
+ $resultInstance = $this->getWrapperInstance()->getUnpublishedEntriesInstance();
+
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+ assert($resultInstance->valid());
+
+ // "Walk" through all entries
+ while ($resultInstance->next()) {
+ // Get current entry
+ $current = $resultInstance->current();
+
+ // Make sure only valid entries pass
+ // @TODO Maybe add more small checks?
+ assert(is_array($current));
+
+ // ... and push it to the next stack
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] Pushing entry with ' . count($current) . ' elements to stack ' . self::STACKER_NAME_PENDING_PUBLISHING . ' ...');
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_PENDING_PUBLISHING, $current);
+ } // END - while
+ }
+
+ /**
+ * Checks whether there are entries pending publication
+ *
+ * @return $isPending Whether there are entries pending publication
+ */
+ public function hasEntriesPendingPublication () {
+ // Determine it if it is not empty
+ $isPending = ($this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PENDING_PUBLISHING) === FALSE);
+
+ // Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] isPending=' . intval($isPending));
+ return $isPending;
+ }
+
+ /**
+ * Whether this DHT's state is 'booting'
+ *
+ * @return $isBooting Whether this DHT is currently booting
+ */
+ public function ifDhtIsBooting () {
+ // Call state instance
+ $isBooting = $this->getStateInstance()->ifDhtIsBooting();
+
+ // Return status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] isBooting=' . intval($isBooting));
+ return $isBooting;
+ }
+
+ /**
+ * Publishes next entry found in stack. This method shall also update the
+ * corresponding dabase entry.
+ *
+ * @return void
+ * @todo Find out if loadDescriptorXml() can be called only once to avoid a lot methods working.
+ */
+ public function publishEntry () {
+ // This test must not fail
+ assert($this->hasEntriesPendingPublication());
+
+ // Is there an instance?
+ if (!$this->publishHelperInstance instanceof HelpableDht) {
+ // Get a helper instance
+ $this->publishHelperInstance = ObjectFactory::createObjectByConfiguredName('dht_publish_entry_helper_class');
+ } // END - if
+
+ // Load the announcement descriptor
+ $this->publishHelperInstance->loadDescriptorXml($this);
+
+ // "Pop" next entry
+ $entry = $this->getStackInstance()->popNamed(self::STACKER_NAME_PENDING_PUBLISHING);
+
+ // Some sanity-checks
+ assert(is_array($entry));
+
+ // Remove any non-public data the database layer desires
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT[' . __METHOD__ . ':' . __LINE__ . ']: Calling this->getWrapperInstance()->removeNonPublicDataFromArray(data) ...');
+ $entry = $this->getWrapperInstance()->removeNonPublicDataFromArray($entry);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT[' . __METHOD__ . ':' . __LINE__ . ']: entry[]=' . gettype($entry));
+
+ // Some sanity-checks again
+ assert(is_array($entry));
+
+ // Assign multiple variables
+ $this->publishHelperInstance->getTemplateInstance()->assignMultipleVariables($entry);
+
+ // "Publish" the descriptor by sending it to the bootstrap/list nodes
+ $this->publishHelperInstance->sendPackage($this);
+ }
+
+ /**
+ * Whether the DHT has fully bootstrapped (after state 'booting')
+ *
+ * @return $isFullyBooted Whether the DHT is fully booted
+ * @todo 0% done
+ */
+ public function hasFullyBootstrapped () {
+ // Get state and check it
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Enable DHT bootstrap request acceptance for local node
+ *
+ * @return void
+ * @todo Switch flag 'accept_bootstrap'
+ */
+ public function enableAcceptDhtBootstrap () {
+ // Call method on database wrapper
+ $this->getWrapperInstance()->enableAcceptDhtBootstrap();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Node DHT facade class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $dhtInstance An instance of a Distributable class
+ */
+ public final static function createNodeDhtFacade () {
+ // Get new instance
+ $dhtInstance = new NodeDhtFacade();
+
+ // Get a database wrapper instance
+ $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_dht_db_wrapper_class');
+
+ // Set it in this class
+ $dhtInstance->setWrapperInstance($wrapperInstance);
+
+ // Return the prepared instance
+ return $dhtInstance;
+ }
+
+ /**
+ * Registers/updates an entry in the DHT with given data from $dhtData
+ * array. Different DHT implemtations may handle this differently as they
+ * may enrich the data with more meta data.
+ *
+ * @param $dhtData A valid array with DHT-related data (e.g. node/peer data)
+ * @return void
+ * @todo Does this data need to be enriched with more meta data?
+ */
+ protected function insertDataIntoDht (array $dhtData) {
+ // Check if there is already an entry for given node_id
+ if ($this->getWrapperInstance()->isNodeRegistered($dhtData)) {
+ /*
+ * Update existing record. Please note that this step is not secure
+ * (e.g. DHT poisoning) it would be good to implement some checks if
+ * the both node owner trust each other (see sub-project 'DSHT').
+ */
+ $this->getWrapperInstance()->updateNode($dhtData);
+ } else {
+ /*
+ * Inserts given node data into the DHT. As above, this step does
+ * currently not perform any security checks.
+ */
+ $this->getWrapperInstance()->registerNode($dhtData);
+ }
+ }
+
+ /**
+ * Initializes the distributed hash table (DHT)
+ *
+ * @return void
+ */
+ public function initDht () {
+ // Is the local node registered?
+ if ($this->getWrapperInstance()->isLocalNodeRegistered()) {
+ // Then only update session id
+ $this->getWrapperInstance()->updateLocalNode();
+ } else {
+ // No, so register it
+ $this->getWrapperInstance()->registerLocalNode();
+ }
+
+ // Change state
+ $this->getStateInstance()->dhtHasInitialized();
+ }
+
+ /**
+ * Bootstraps the DHT by sending out a message to all available nodes
+ * (including itself). This step helps the node to get to know more nodes
+ * which can be queried later for object distribution.
+ *
+ * @return void
+ */
+ public function bootstrapDht () {
+ // Get a helper instance
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('dht_bootstrap_helper_class');
+
+ // Load the announcement descriptor
+ $helperInstance->loadDescriptorXml($this);
+
+ // Compile all variables
+ $helperInstance->getTemplateInstance()->compileConfigInVariables();
+
+ // "Publish" the descriptor by sending it to the bootstrap/list nodes
+ $helperInstance->sendPackage($this);
+
+ // Change state
+ $this->getStateInstance()->dhtIsBooting();
+ }
+
+ /**
+ * Finds a node locally by given session id
+ *
+ * @param $sessionId Session id to lookup
+ * @return $nodeData Node-data array
+ */
+ public function findNodeLocalBySessionId ($sessionId) {
+ // Default is empty data array
+ $nodeData = array();
+
+ /*
+ * Call the wrapper to do the job and get back a result instance. There
+ * will come back zero or one entry from the wrapper.
+ */
+ $resultInstance = $this->getWrapperInstance()->findNodeLocalBySessionId($sessionId);
+
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+
+ // Is the next entry valid?
+ if (($resultInstance->valid()) && ($resultInstance->next())) {
+ /*
+ * Then load the first entry (more entries are being ignored and
+ * should not happen).
+ */
+ $nodeData = $resultInstance->current();
+ } // END - if
+
+ // Return node data
+ return $nodeData;
+ }
+
+ /**
+ * Registers an other node with this node by given message data. The
+ * following data must always be present:
+ *
+ * - session-id (for finding the node's record together with below data)
+ * - external-address (hostname or IP number)
+ * - listen-port (TCP/UDP listen port for inbound connections)
+ *
+ * @param $messageArray An array with all minimum message data
+ * @param $handlerInstance An instance of a HandleableDataSet class
+ * @param $forceUpdate Optionally force update, don't register (default: register if not found)
+ * @return void
+ * @throws NodeSessionIdVerficationException If the node was not found and update is forced
+ */
+ public function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, $forceUpdate = FALSE) {
+ // Get a search criteria class
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE) . ',handlerInstance=' . $handlerInstance->__toString() . ',forceUpdate=' . intval($forceUpdate) . ',count(getSearchData())=' . count($handlerInstance->getSearchData()));
+
+ // Search for the node's session id and external address/hostname + TCP/UDP listen port
+ foreach ($handlerInstance->getSearchData() as $key) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getPrintableState() . ',key=' . $key);
+
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData[' . $key . ']=' . $messageData[$key]);
+
+ // Add criteria
+ $searchInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
+ } // END - foreach
+
+ // Only one entry is fine
+ $searchInstance->setLimit(1);
+
+ // Run the query
+ $resultInstance = $this->getWrapperInstance()->doSelectByCriteria($searchInstance);
+
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+
+ // Is there already an entry?
+ if ($resultInstance->valid()) {
+ // Entry found, so update it
+ $this->getWrapperInstance()->updateNodeByMessageData($messageData, $handlerInstance, $searchInstance);
+ } elseif ($forceUpdate === FALSE) {
+ // Nothing found, so register it
+ $this->getWrapperInstance()->registerNodeByMessageData($messageData, $handlerInstance);
+ } else {
+ /*
+ * Do not register non-existent nodes here. This is maybe fatal,
+ * caused by "stolen" session id and/or not matching address.
+ */
+ throw new NodeSessionIdVerficationException(array($this, $messageData), BaseHubSystem::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING);
+ }
+
+ // Save last exception
+ $handlerInstance->setLastException($this->getWrapperInstance()->getLastException());
+ }
+
+ /**
+ * Queries the local DHT data(base) for a node list with all supported
+ * object types except the node by given session id.
+ *
+ * @param $messageData An array with message data from a node_list request
+ * @param $handlerInstance An instance of a HandleableDataSet class
+ * @param $excludeKey Array key which should be excluded
+ * @param $andKey Array of $separator-separated list of elements which all must match
+ * @param $separator Sepator char (1st parameter for explode() call)
+ * @return $nodeList An array with all found nodes
+ */
+ public function queryLocalNodeListExceptByMessageData (array $messageData, HandleableDataSet $handlerInstance, $excludeKey, $andKey, $separator) {
+ // Make sure both keys are there
+ assert((isset($messageData[$excludeKey])) && (isset($messageData[$andKey])));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE));
+
+ // Get a search criteria class
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Add all keys
+ foreach (explode($separator, $messageData[$andKey]) as $criteria) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: andKey=' . $andKey . ',criteria=' . $criteria);
+
+ // Add it and leave any 'my-' prefix out
+ $searchInstance->addChoiceCriteria(str_replace('my-', '', $andKey), $criteria);
+ } // END - foreach
+
+ // Add exclusion key
+ $searchInstance->addExcludeCriteria(str_replace('my-', '', $excludeKey), $messageData[$excludeKey]);
+
+ // Only X entries are fine
+ $searchInstance->setLimit($this->getConfigInstance()->getConfigEntry('node_dht_list_limit'));
+
+ // Run the query
+ $resultInstance = $this->getWrapperInstance()->doSelectByCriteria($searchInstance);
+
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+ assert($resultInstance->valid());
+
+ // Init array
+ $nodeList = array();
+
+ // Get node list
+ while ($resultInstance->next()) {
+ // Get current element (it should be an array, and have at least 1 entry)
+ $current = $resultInstance->current();
+ assert(is_array($current));
+ assert(count($current) > 0);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: current(' . count($current) . ')[' . gettype($current) . ']=' . print_r($current, TRUE));
+
+ /*
+ * Remove some keys as they should not be published.
+ */
+ unset($current[$this->getWrapperInstance()->getIndexKey()]);
+
+ // Add this entry
+ array_push($nodeList, $current);
+ } // END - while
+
+ // Save last exception
+ $handlerInstance->setLastException($this->getWrapperInstance()->getLastException());
+
+ // Return node list (array)
+ return $nodeList;
+ }
+
+ /**
+ * Inserts given node list array (from earlier database result produced by
+ * an other node) into the DHT. This array origins from above method
+ * queryLocalNodeListExceptByMessageData().
+ *
+ * @param $nodeList An array from an earlier database result instance
+ * @return void
+ */
+ public function insertNodeList (array $nodeList) {
+ // If no node is in the list (array), skip the rest of this method
+ if (count($nodeList) == 0) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: No node record has been returned.');
+
+ // Abort here
+ return;
+ } // END - if
+
+ // Put them all into a stack
+ foreach ($nodeList as $nodeData) {
+ // Insert all entries
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_INSERT_NODE, $nodeData);
+ } // END - foreach
+ }
+
+ /**
+ * Find recipients for given package data
+ *
+ * @param $packageData An array of valid package data
+ * @return $recipients An indexed array with DHT recipients
+ */
+ public function findRecipientsByPackageData (array $packageData) {
+ // Query get a result instance back from DHT database wrapper.
+ $resultInstance = $this->getWrapperInstance()->getResultFromExcludedSender($packageData);
+
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+
+ // No entries found?
+ if (!$resultInstance->valid()) {
+ // Then skip below loop
+ return array();
+ } // END - if
+
+ // Init array
+ $recipients = array();
+
+ // Search for all recipients
+ while ($resultInstance->next()) {
+ // Get current entry
+ $current = $resultInstance->current();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: current=' . print_r($current, TRUE));
+
+ // Add instance to recipient list
+ array_push($recipients, $current);
+ } // END - while
+
+ // Return filled array
+ return $recipients;
+ }
+
+ /**
+ * Finds DHT recipients by given key/value pair
+ *
+ * @param $key Key to search for
+ * @param $value Value to check on found key
+ * @return $recipiens Array with DHT recipients from given key/value pair
+ */
+ public function findRecipientsByKey ($key, $value) {
+ // Look for all suitable nodes
+ $resultInstance = $this->getWrapperInstance()->getResultFromKeyValue($key, $value);
+
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+ assert($resultInstance->valid());
+
+ // Init array
+ $recipients = array();
+
+ // "Walk" through all entries
+ while ($resultInstance->next()) {
+ // Get current entry
+ $current = $resultInstance->current();
+
+ // Add instance to recipient list
+ array_push($recipients, $current);
+ } // END - while
+
+ // Return filled array
+ return $recipients;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A !!! discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 !!!Discovery extends BaseNodeDiscovery implements Discoverable,,,, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Create an instance of this class
+ *
+ * @return $discoveryInstance An instance of this discovery class
+ */
+ public static final function create!!!Discovery () {
+ // Get an instance of this class
+ $discoveryInstance = new !!!Discovery();
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general node discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseNodeDiscovery extends BaseDiscovery implements Discoverable {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real class name
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A UniversalNodeLocator discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements DiscoverableUniversalNodeLocator, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Create an instance of this class
+ *
+ * @return $discoveryInstance An instance of this discovery class
+ */
+ public static final function createUniversalNodeLocatorDiscovery () {
+ // Get an instance of this class
+ $discoveryInstance = new UniversalNodeLocatorDiscovery();
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+
+ /**
+ * "Discovers" an instance of a LocateableNode class for given NodeHelper class
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return $unlInstance An instance of a LocateableNode class
+ */
+ public function discoverUniversalNodeLocatorByNode (NodeHelper $nodeInstance) {
+ /*
+ * First get an instance from the configured hub communication protocol
+ * type (which is mostly TCP, so you get a TcpProtocolResolver here).
+ */
+ $resolverInstance = ProtocolResolverFactory::createResolverFromConfiguredProtocol();
+
+ // Then resolve the node instance into an UNL instance
+ $unlInstance = $resolverInstance->resolveUniversalNodeLocatorFromNodeHelper($nodeInstance);
+
+ // ... and return it
+ return $unlInstance;
+ }
+
+ /**
+ * "Discovers" the full universal node locator for given configuration entry
+ * which should represent the address part of the UNL. In case of an IP
+ * address, this *must not* include the port number as this is being found
+ * out for you.
+ *
+ * Valid values for $configKey: internal,external
+ *
+ * @param $configKey Key for address to get (valid: internal,external)
+ * @return $unl Universal node locator
+ */
+ public function discoverUniversalNodeLocatorByConfiguredAddress ($configKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('UNL-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']:configKey=' . $configKey . ' - CALLED!');
+
+ // Is there cache?
+ if (!isset($GLOBALS[__METHOD__][$configKey])) {
+ // Validate config key
+ assert(($configKey == 'internal') || ($configKey == 'external'));
+
+ /*
+ * First get an instance from the configured hub communication protocol
+ * type (which is mostly TCP, so you get a TcpProtocolResolver here).
+ */
+ $resolverInstance = ProtocolResolverFactory::createResolverFromConfiguredProtocol();
+
+ // Get back the full UNL
+ $GLOBALS[__METHOD__][$configKey] = $resolverInstance->resolveUniversalNodeLocatorFromConfigKey($configKey);
+ } // END - if
+
+ // Return cached value
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('UNL-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']:configKey=' . $configKey . ',unl=' . $GLOBALS[__METHOD__][$configKey] . ' - EXIT!');
+ return $GLOBALS[__METHOD__][$configKey];
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Protocol discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtocol, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Create an instance of this class
+ *
+ * @return $discoveryInstance An instance of this discovery class
+ */
+ public static final function createProtocolDiscovery () {
+ // Get an instance of this class
+ $discoveryInstance = new ProtocolDiscovery();
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+
+ /**
+ * Determines the protoctol name
+ *
+ * @param $packageData Valid package data
+ * @return $protocolInstance An instance of a HandleableProtocol class
+ */
+ public static final function determineProtocolByPackageData (array $packageData) {
+ // First we need a tags instance
+ $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+ /*
+ * We need to decide here which socket (TCP or UDP) should be used for
+ * the actual data transmission. In this process we will find out if
+ * the recipient of this package has already a known (registered) socket
+ * and if so we can re-use it. If there is no socket registered, we try
+ * to make a new connection to the given Universal Node Locator.
+ */
+ $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
+
+ // Return it
+ return $protocolInstance;
+ }
+
+ /**
+ * "Discovers" the protocol type from given raw package data. This is done
+ * by looking at the 'recipient' field and extract the first part from it.
+ *
+ * @param $packageData Raw package data
+ * @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
+ */
+ public static final function discoverProtocolByPackageData (array $packageData) {
+ //* DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
+
+ /*
+ * "Explode" the 'recipient' array element into a new one, giving at
+ * least two entries: protocol://address
+ */
+ $recipient = explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // At least 2 entries must be found
+ assert(count($recipient) >= 2);
+
+ // Now get the first part (protocol type) and make all lower-case
+ $protocolType = strtolower($recipient[0]);
+
+ // Return it
+ // @TODO Add some validation here???
+ return $protocolType;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A !!! recipient discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 !!!RecipientDiscovery extends BaseRecipientDiscovery implements Discoverable,,,Recipient, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Create an instance of this class
+ *
+ * @return $discoveryInstance An instance of this discovery class
+ */
+ public static final function create!!!Discovery () {
+ // Get an instance of this class
+ $discoveryInstance = new !!!Discovery();
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A PackageRecipient discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseRecipientDiscovery extends BaseNodeDiscovery implements DiscoverableRecipient {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real class name
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ /*
+ * Get recipients list instance and set it here for all discovery
+ * implementations.
+ */
+ $listInstance = RecipientListFactory::createRecipientListInstance();
+ $this->setListInstance($listInstance);
+ }
+
+ /**
+ * "Getter" for recipient iterator
+ *
+ * @return$iteratorInstance An instance of a Iterateable object
+ */
+ public final function getIterator () {
+ // Get iterator from it
+ $iteratorInstance = $this->getListInstance()->getIterator();
+
+ // Return it
+ return $iteratorInstance;
+ }
+
+ /**
+ * Clears all recipients for e.g. another package to deliver. This method
+ * simply clears the inner list instance.
+ *
+ * @return void
+ */
+ public final function clearRecipients () {
+ // Clear the list
+ $this->getListInstance()->clearList();
+ }
+
+ /**
+ * Checks whether the recipient list is empty
+ *
+ * @return $isEmpty Whether the recipient list is empty
+ */
+ public final function isRecipientListEmpty () {
+ // Check it ...
+ $isEmpty = ($this->getListInstance()->count() == 0);
+
+ // Return it
+ return $isEmpty;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A DhtRecipient discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableDhtRecipient, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Create an instance of this class
+ *
+ * @return $discoveryInstance An instance of this discovery class
+ */
+ public static final function createDhtRecipientDiscovery () {
+ // Get an instance of this class
+ $discoveryInstance = new DhtRecipientDiscovery();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set it here
+ $discoveryInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+
+ /**
+ * Resolves one or more recipients for a DHT transfer by given package data.
+ *
+ * @param $packageData Valid package data array
+ * @return $recipients An indexed array with DHT recipients
+ */
+ public function resolveRecipientsByPackageData (array $packageData) {
+ // Use facade to get recipients back
+ $recipients = $this->getDhtInstance()->findRecipientsByPackageData($packageData);
+
+ // Return it
+ return $recipients;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A PackageRecipient discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableNodeRecipient, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Create an instance of this class
+ *
+ * @return $discoveryInstance An instance of this discovery class
+ */
+ public static final function createPackageRecipientDiscovery () {
+ // Get an instance of this class
+ $discoveryInstance = new PackageRecipientDiscovery();
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+
+ /**
+ * Tries to discover all recipients for given package data
+ *
+ * @param $packageData Raw package data array
+ * @return void
+ */
+ public function discoverRecipients (array $packageData) {
+ // This must be available
+ //* DEBUG: */ print $this->__toString() . ': packageData=' . print_r($packageData, TRUE);
+ assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+
+ // First try out the direct recipient (session id)
+ try {
+ // Get instance (should not break)
+ $recipientInstance = ObjectFactory::createObjectByConfiguredName('direct_recipient_class');
+
+ // Try to solve it
+ $recipientInstance->resolveRecipient($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance(), $packageData);
+ } catch (FrameworkException $e) {
+ // Didn't work, so try the non-generic, depending recipient field itself (this may fail)
+ try {
+ // Try to find the right class
+ $recipientInstance = ObjectFactory::createObjectByConfiguredName(strtolower($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) . '_recipient_class');
+
+ // And try to solve again
+ $recipientInstance->resolveRecipient($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance(), $packageData);
+ } catch (FrameworkException $e) {
+ // Could not find class, what ever failed
+ $this->debugInstance($e->getMessage());
+ }
+ }
+ }
+
+ /**
+ * Tries to discover all recipients by given decoded package data.
+ *
+ * @param $decodedData Raw raw package data array
+ * @return void
+ * @todo Add some validation of recipient field, e.g. an Universal Node Locator is found
+ * @todo Enrich both messages with recipient data
+ */
+ public function discoverRawRecipients (array $decodedData) {
+ // This must be available
+ assert(isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+
+ // First clear all recipients
+ $this->clearRecipients();
+
+ // Get a protocol handler back from decoded data
+ $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($decodedData);
+
+ // Is the 'recipient' field same as this peer's IP?
+ if ($handlerInstance->isOwnAddress($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
+ /*
+ * Is same as own external address + TCP/UDP listen port or
+ * internal address, don't do anything here so other classes found
+ * an empty recipient list for internal (own) handling of the
+ * original content.
+ */
+
+ // Debug output (may flood)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' matches own ip (external=' . HubTools::determineOwnExternalAddress() . ' or internal=' . HubTools::determineOwnInternalAddress() . ')');
+ } else {
+ // Debug output (may flood)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' is different than own external address (' . HubTools::determineOwnExternalAddress() . ') nor internal address (' . HubTools::determineOwnInternalAddress() . '), need to forward (not yet implemented)!');
+
+ // This package is to be delivered to someone else, so add it
+ // @TODO Unfinished: $this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+ }
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A socket discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageSocketDiscovery extends BaseRecipientDiscovery implements DiscoverableSocket, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Create an instance of this class
+ *
+ * @return $discoveryInstance An instance of this discovery class
+ */
+ public static final function createPackageSocketDiscovery () {
+ // Get an instance of this class
+ $discoveryInstance = new PackageSocketDiscovery();
+
+ // Output debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Initialized.');
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+
+ /**
+ * Tries to dicover the right listener instance
+ *
+ * @param $protocolInstance An instance of a HandleableProtocol class
+ * @param $packageData Raw package data
+ * @return $listenerInstance An instance of a Listenable instance or null
+ */
+ public function discoverListenerInstance (HandleableProtocol $protocolInstance, array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolInstance=' . $protocolInstance->__toString() . ' - CALLED!');
+
+ /*
+ * Get the listener pool instance, we need to lookup the matching
+ * listener->poolInstance chain there.
+ */
+ $poolInstance = NodeObjectFactory::createNodeInstance()->getListenerPoolInstance();
+
+ // Init listener instance
+ $listenerInstance = NULL;
+
+ // Get handler name
+ $protocolName = $protocolInstance->getProtocolName();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ',poolEntriesInstance=' . $poolInstance->getPoolEntriesInstance()->__toString());
+
+ /*
+ * Now we need to choose again. It is whether we are speaking with a hub
+ * or with a client. So just handle it over to all listeners in this
+ * pool.
+ */
+ foreach ($poolInstance->getPoolEntriesInstance()->getArrayFromList($protocolName) as $listenerInstance) {
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ',listenerInstance[' . gettype($listenerInstance) . ']=' . $listenerInstance);
+
+ // Make sure the instance is valid
+ assert($listenerInstance instanceof Listenable);
+
+ // Does the listener want that package?
+ if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) {
+ // This listener likes our package data, so abort here
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Listener is accepting package data.');
+ break;
+ } // END - if
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Listener is NOT accepting package data.');
+ } // END - foreach
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: listenerInstance=' . $listenerInstance->__toString());
+
+ // Return it
+ return $listenerInstance;
+ }
+
+ /**
+ * Tries to discover the right socket for given package data and returns a
+ * matching socket resource for that protocol.
+ *
+ * @param $packageData Raw package data array
+ * @param $connectionType Type of connection, can be 'incoming' or 'outgoing', *NEVER* 'server'!
+ * @return $socketResource A valid socket resource or FALSE if an error occured
+ * @throws NoListGroupException If the procol group is not found in peer list
+ * @throws NullPointerException If listenerInstance is NULL
+ * @throws InvalidUnlException If the provided UNL cannot be validated by the protocol handler
+ */
+ public function discoverSocket (array $packageData, $connectionType) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: connectionType=' . $connectionType . ' - CALLED!');
+
+ // Assert on type and recipient
+ assert($connectionType != BaseConnectionHelper::CONNECTION_TYPE_SERVER);
+ assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+
+ // Determine protocol instance
+ $protocolInstance = ProtocolDiscovery::determineProtocolByPackageData($packageData);
+
+ // Is it valid?
+ assert($protocolInstance instanceof HandleableProtocol);
+
+ // Does the UNL validate?
+ if (!$protocolInstance->isValidUniversalNodeLocatorByPackageData($packageData)) {
+ // Not valid, throw exception
+ throw new InvalidUnlException(array($this, $protocolInstance, $packageData), BaseHubSystem::EXCEPTION_INVALID_UNL);
+ } // END - if
+
+ // Get the listener instance
+ $listenerInstance = $this->discoverListenerInstance($protocolInstance, $packageData);
+
+ // If there is no listener who wants to have that package, we simply drop it here
+ if (is_null($listenerInstance)) {
+ // Abort with no resource
+ throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ } // END - if
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE));
+
+ /*
+ * Now we have the listener instance, we can determine the right
+ * resource to continue. The first step is to get the attached pool
+ * instance and pass over the whole package data to get the right
+ * socket.
+ */
+ $socketResource = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData, $connectionType);
+
+ // Debug message
+ // @TODO FIXME: I don't like these abuse of variables, better strict types
+ if (is_resource($socketResource)) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',error=' . socket_strerror(socket_last_error($socketResource)) . ',packageData=' . print_r($packageData, TRUE));
+ } else {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',packageData=' . print_r($packageData, TRUE));
+ }
+
+ // Is it FALSE, the recipient isn't known to us and we have no connection to it
+ if (($socketResource === FALSE) || (!is_resource($socketResource)) || (socket_last_error($socketResource) > 0)) {
+ // Try to create a new socket resource
+ try {
+ // Possibly noisy debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to establish a ' . strtoupper($protocolInstance) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
+
+ // Get a socket resource from our factory (if succeeded)
+ $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolInstance);
+ } catch (SocketConnectionException $e) {
+ // The connection fails of being established, so log it away
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Caught ' . $e->__toString() . ',message=' . $e->getMessage());
+ }
+ } // END - if
+
+ // Try to resolve the socket resource
+ try {
+ // Get the helper instance from registry
+ $helperInstance = Registry::getRegistry()->getInstance('connection');
+
+ // Possibly noisy debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Going to resolve socket from peer state and given package data ...');
+
+ // Resolve the peer's state (but ignore return value)
+ PeerStateResolver::resolveStateByPackage($helperInstance, $packageData, $socketResource);
+ } catch (InvalidSocketException $e) {
+ // This cannot be fixed, so log it away
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Cannot discover socket resource for recipient ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ': ' . $e->getMessage());
+
+ // Make any failed attempts to 'FALSE'
+ $socketResource = FALSE;
+ }
+
+ // And return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: socketResource=' . $socketResource . ',packageData=' . print_r($packageData, TRUE));
+ return $socketResource;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for network packages
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageFilterChainFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a filter chain by given tags array.
+ *
+ * @param $tags An array with tags from a package
+ * @return $chainInstance An instance of a filter chain class
+ */
+ public static final function createChainByTagsArray (array $tags) {
+ // Get a registry key from tags array, this does mostly call implode()
+ $registryKey = Registry::getRegistryKeyFromArray('package_filter_chain', $tags);
+
+ // Is the registry key there?
+ if (Registry::getRegistry()->instanceExists($registryKey)) {
+ // Yes, then use that instance
+ $chainInstance = Registry::getRegistry()->getInstance($registryKey);
+ } else {
+ // Initialize a filter chain class
+ $chainInstance = self::createObjectByConfiguredName('package_filter_chain_class');
+
+ // "Walk" through all tags entries
+ foreach ($tags as $tag) {
+ /*
+ * Now create a filter instance of this tag. This way all tags
+ * got rudymentary verified, if an exception is coming here, it
+ * simply means the tag is not valid. This however should be
+ * handled some calls before this method is called.
+ */
+ $filterInstance = self::createObjectByConfiguredName('package_tag_' . $tag . '_filter');
+
+ // Add this filter to the chain
+ $chainInstance->addFilter($filterInstance);
+ } // END - foreach
+
+ // Add the finished chain to the registry
+ Registry::getRegistry()->addInstance($registryKey, $chainInstance);
+ }
+
+ // Return the chain instance
+ return $chainInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for chunk handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ChunkHandlerFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) chunk handler instance
+ *
+ * @return $handlerInstance An instance of a chunk handler class
+ */
+ public static final function createChunkHandlerInstance () {
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists('chunk_handler')) {
+ // Get handler from registry
+ $handlerInstance = Registry::getRegistry()->getInstance('chunk_handler');
+ } else {
+ // Get the handler instance
+ $handlerInstance = self::createObjectByConfiguredName('chunk_handler_class');
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('chunk_handler', $handlerInstance);
+ }
+
+ // Return the instance
+ return $handlerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A factory class for !!!
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Factory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) !!! instance
+ *
+ * @return $%%%Instance An instance of a !!! class
+ */
+ public static final function create???Instance () {
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists('|||')) {
+ // Get handler from registry
+ $%%%Instance = Registry::getRegistry()->getInstance('|||');
+ } else {
+ // Get the handler instance
+ $%%%Instance = self::createObjectByConfiguredName('|||_class');
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('|||', $%%%Instance);
+ }
+
+ // Return the instance
+ return $%%%Instance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for communicator
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014, 2015 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 CommunicatorFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton communicator instance. If no instance is found, it fill
+ * be generated and stored in registry, else the communicator from the
+ * registry will be returned.
+ *
+ * @param $configEntry A configuration entry naming the real class' name
+ * @parasm $communicatorType Type of the communicator, can currently be 'node'
+ * @return $communicatorInstance A communicator instance
+ */
+ public static final function createCommunicatorInstance ($configEntry, $communicatorType) {
+ // If there is no communicator?
+ if (Registry::getRegistry()->instanceExists($communicatorType . '_communicator')) {
+ // Get communicator from registry
+ $communicatorInstance = Registry::getRegistry()->getInstance($communicatorType . '_communicator');
+ } else {
+ // Get the communicator instance
+ $communicatorInstance = self::createObjectByConfiguredName($configEntry);
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance($communicatorType . '_communicator', $communicatorInstance);
+ }
+
+ // Return the instance
+ return $communicatorInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for Decodeable objects
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 DecoderFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) Decodeable instance
+ *
+ * @return $decoderInstance An instance of a Decodeable class
+ */
+ public static final function createPackageDecoderInstance () {
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists('package_decoder')) {
+ // Get handler from registry
+ $decoderInstance = Registry::getRegistry()->getInstance('package_decoder');
+ } else {
+ // Get a chunk handler instance
+ $handlerInstance = ChunkHandlerFactory::createChunkHandlerInstance();
+
+ // Get the handler instance
+ $decoderInstance = self::createObjectByConfiguredName('package_decoder_class', array($handlerInstance));
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('package_decoder', $decoderInstance);
+ }
+
+ // Return the instance
+ return $decoderInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for DHT objects
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtObjectFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) DHT object instance
+ *
+ * @param $prefix Prefix for DHT class name and registry key
+ * @return $dhtInstance An instance of a DHT object class
+ */
+ public static final function createDhtInstance ($prefix) {
+ // Set instance name
+ $name = $prefix . '_dht';
+
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists($name)) {
+ // Get handler from registry
+ $dhtInstance = Registry::getRegistry()->getInstance($name);
+ } else {
+ // Get the handler instance
+ $dhtInstance = self::createObjectByConfiguredName($name . '_class');
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance($name, $dhtInstance);
+ }
+
+ // Return the instance
+ return $dhtInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for package discovery
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageDiscoveryFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * 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.
+ *
+ * @return $discoveryInstance A package discovery instance
+ */
+ public static final function createPackageDiscoveryInstance () {
+ // Do we have an instance in the registry?
+ if (Registry::getRegistry()->instanceExists('package_discovery')) {
+ // Then use this instance
+ $discoveryInstance = Registry::getRegistry()->getInstance('package_discovery');
+ } else {
+ // Create a new instance
+ $discoveryInstance = self::createObjectByConfiguredName('package_recipient_discovery_class');
+
+ // Set the instance in registry for further use
+ Registry::getRegistry()->addInstance('package_discovery', $discoveryInstance);
+ }
+
+ // Return the instance
+ return $discoveryInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A factory class for socket discovery
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 SocketDiscoveryFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton network socket 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.
+ *
+ * @return $discoveryInstance A socket discovery instance
+ */
+ public static final function createSocketDiscoveryInstance () {
+ // Do we have an instance in the registry?
+ if (Registry::getRegistry()->instanceExists('socket_discovery')) {
+ // Then use this instance
+ $discoveryInstance = Registry::getRegistry()->getInstance('socket_discovery');
+ } else {
+ // Create a new instance
+ $discoveryInstance = self::createObjectByConfiguredName('socket_discovery_class');
+
+ // Set the instance in registry for further use
+ Registry::getRegistry()->addInstance('socket_discovery', $discoveryInstance);
+ }
+
+ // Return the instance
+ return $discoveryInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for message type handlers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 MessageTypeHandlerFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton message type handler instance. If an instance is
+ * found in registry, it will be returned, else a new instance is created
+ * and stored in the same registry entry.
+ *
+ * @param $messageType Message type to create an object from
+ * @return $handlerInstance A message type handler instance
+ */
+ public static final function createMessageTypeHandlerInstance ($messageType) {
+ // Do we have an instance in the registry?
+ if (Registry::getRegistry()->instanceExists('message_type_' . $messageType . '_handler')) {
+ // Then use this instance
+ $handlerInstance = Registry::getRegistry()->getInstance('message_type_' . $messageType . '_handler');
+ } else {
+ // Now prepare the tags instance
+ $handlerInstance = self::createObjectByConfiguredName('message_type_' . $messageType . '_handler_class');
+
+ // Set the instance in registry for further use
+ Registry::getRegistry()->addInstance('message_type_' . $messageType . '_handler', $handlerInstance);
+ }
+
+ // Return the instance
+ return $handlerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A factory class for protocol handlers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Unfinished stuff
+ *
+ * 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 ProtocolHandlerFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a protocol handler based on given protocol type. This is mostly 'tcp'.
+ *
+ * @param $protocolType Protocol type to create/return a protocol handler instance for
+ * @return $handlerInstance A protocol handler instance
+ */
+ private static function createProtocolHandlerByType ($protocolType) {
+ // Do we have an instance in the registry?
+ if (Registry::getRegistry()->instanceExists($protocolType . '_protocol_handler')) {
+ // Then use this instance
+ $handlerInstance = Registry::getRegistry()->getInstance($protocolType . '_protocol_handler');
+ } else {
+ // Now prepare the tags instance
+ $handlerInstance = self::createObjectByConfiguredName($protocolType . '_protocol_handler_class');
+
+ // Set the instance in registry for further use
+ Registry::getRegistry()->addInstance($protocolType . '_protocol_handler', $handlerInstance);
+ }
+
+ // Return the instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Returns a singleton protocol handler instance from given HubHelper
+ * instance. If an instance is found in registry, it will be returned, else
+ * a new instance is created and stored in the same registry entry.
+ *
+ * @param $helperInstance An instance of a HubHelper class
+ * @return $handlerInstance A protocol handler instance
+ */
+ public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) {
+ // Get the protocol type from given helper instance
+ $protocolType = $helperInstance->determineProtocolType();
+
+ // Call super factory method
+ return self::createProtocolHandlerByType($protocolType);
+ }
+
+ /**
+ * Creates an instance of a protocol handler from given (raw) package data
+ *
+ * @param $packageData An array with raw package data
+ * @return $handlerInstance A protocol handler instance
+ */
+ public static final function createProtocolHandlerFromPackageData (array $packageData) {
+ // "Discover" the protocol type
+ $protocolType = ProtocolDiscovery::discoverProtocolByPackageData($packageData);
+
+ // Call super factory method
+ return self::createProtocolHandlerByType($protocolType);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for ShareableInfo
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ConnectionInfoFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) ShareableInfo instance
+ *
+ * @param $protocolName Name of protocol (e.g. 'tcp')
+ * @param $type Connection type ('listener' or 'helper')
+ * @return $infoInstance An instance of a ShareableInfo class
+ */
+ public static final function createConnectionInfoInstance ($protocolName, $type) {
+ // Generate key
+ $key = 'connection_info_' . $protocolName . '_' . $type;
+
+ // If there is no info?
+ if (Registry::getRegistry()->instanceExists($key)) {
+ // Get info from registry
+ $infoInstance = Registry::getRegistry()->getInstance($key);
+ } else {
+ // Get the info instance
+ $infoInstance = self::createObjectByConfiguredName('connection_info_class');
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance($key, $infoInstance);
+ }
+
+ // Return the instance
+ return $infoInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for recipient lists
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 RecipientListFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * 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.
+ *
+ * @return $listInstance A recipient list instance
+ */
+ public static final function createRecipientListInstance () {
+ // Do we have an instance in the registry?
+ if (Registry::getRegistry()->instanceExists('recipient_list')) {
+ // Then use this instance
+ $listInstance = Registry::getRegistry()->getInstance('recipient_list');
+ } else {
+ // Create a new instance
+ $listInstance = self::createObjectByConfiguredName('recipient_list_class');
+
+ // Set the instance in registry for further use
+ Registry::getRegistry()->addInstance('recipient_list', $listInstance);
+ }
+
+ // Return the instance
+ return $listInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for nodes
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 NodeObjectFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) NodeHelper instance
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return $nodeInstance An instance of a NodeHelper class
+ * @throws FactoryRequiredParameterException If not all parameters are set and no instance 'node' is set.
+ */
+ public static final function createNodeInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) {
+ // Get new factory instance
+ $factoryInstance = new NodeObjectFactory();
+
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists('node')) {
+ // Get handler from registry
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+ } elseif (($requestInstance instanceof Requestable) && ($responseInstance instanceof Responseable)) {
+ // The default node-mode is from our configuration
+ $nodeMode = $factoryInstance->getConfigInstance()->getConfigEntry('node_default_mode');
+
+ // Is the node 'mode' parameter set?
+ if ($requestInstance->isRequestElementSet('mode')) {
+ // Then use this which overrides the config entry temporarily
+ $nodeMode = $requestInstance->getRequestElement('mode');
+ } else {
+ // Set it for easier re-usage
+ $requestInstance->setRequestElement('mode', $nodeMode);
+ }
+
+ // Now convert the node-mode in a class name
+ $className = 'Hub' . $factoryInstance->convertToClassName($nodeMode) . 'Node';
+
+ // Get the node instance
+ $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
+
+ // Get a registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Set the app instance
+ $nodeInstance->setApplicationInstance($applicationInstance);
+
+ // Add node-specific filters
+ $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('node', $nodeInstance);
+ } else {
+ // Throw an exception here
+ throw new FactoryRequiredParameterException($factoryInstance, self::EXCEPTION_FACTORY_REQUIRE_PARAMETER);
+ }
+
+ // Return the instance
+ return $nodeInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for package assembler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageAssemblerFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton assembler instance. If no instance is found, it fill
+ * be generated and stored in registry, else the assembler from the
+ * registry will be returned.
+ *
+ * @param $packageInstance An instance of a Receivable instance
+ * @return $assemblerInstance An instance of a Assembler instance
+ */
+ public static final function createAssemblerInstance (Receivable $packageInstance) {
+ // If there is no assembler?
+ if (Registry::getRegistry()->instanceExists('package_assembler')) {
+ // Get assembler from registry
+ $assemblerInstance = Registry::getRegistry()->getInstance('package_assembler');
+ } else {
+ // Get the assembler instance
+ $assemblerInstance = self::createObjectByConfiguredName('package_assembler_class', array($packageInstance));
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('package_assembler', $assemblerInstance);
+ }
+
+ // Return the instance
+ return $assemblerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A factory class for network packages
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NetworkPackageFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * 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.
+ *
+ * @return $packageInstance A network package instance
+ */
+ public static final function createNetworkPackageInstance () {
+ // 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, ZLIB should be fine but we
+ * keep it open here so you can experiment with the settings and don't
+ * need to touch this code.
+ */
+ $compressorInstance = self::createObjectByConfiguredName('raw_package_compressor_class');
+
+ // Prepare the decorator compressor (for later flawless and easy updates)
+ $compressorInstance = self::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 = self::createObjectByConfiguredName('network_package_class', array($compressorInstance));
+
+ // Set the instance in registry for further use
+ Registry::getRegistry()->addInstance('network_package', $packageInstance);
+ }
+
+ // Return the instance
+ return $packageInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for fragmenter
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 FragmenterFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton fragmenter instance. If no instance is found, it fill
+ * be generated and stored in registry, else the fragmenter from the
+ * registry will be returned.
+ *
+ * @param $fragmenterType The fragmenter's type
+ * @return $fragmenterInstance A fragmenter instance
+ */
+ public static final function createFragmenterInstance ($fragmenterType) {
+ // If there is no fragmenter?
+ if (Registry::getRegistry()->instanceExists($fragmenterType . '_fragmenter')) {
+ // Get fragmenter from registry
+ $fragmenterInstance = Registry::getRegistry()->getInstance($fragmenterType . '_fragmenter');
+ } else {
+ // Get the fragmenter instance
+ $fragmenterInstance = self::createObjectByConfiguredName($fragmenterType . '_fragmenter_class');
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance($fragmenterType . '_fragmenter', $fragmenterInstance);
+ }
+
+ // Return the instance
+ return $fragmenterInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for producer
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ProducerFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton producer instance. If no instance is found, it fill
+ * be generated and stored in registry, else the producer from the
+ * registry will be returned.
+ *
+ * @param $configEntry A configuration entry naming the real class' name
+ * @parasm $producerType Type of the producer, can be 'key', 'test_unit', etc.
+ * @return $producerInstance A producer instance
+ */
+ public static final function createProducerInstance ($configEntry, $producerType) {
+ // If there is no producer?
+ if (Registry::getRegistry()->instanceExists($producerType . '_producer')) {
+ // Get producer from registry
+ $producerInstance = Registry::getRegistry()->getInstance($producerType . '_producer');
+ } else {
+ // Get the producer instance
+ $producerInstance = self::createObjectByConfiguredName($configEntry);
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance($producerType . '_producer', $producerInstance);
+ }
+
+ // Return the instance
+ return $producerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for network packages
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ObjectTypeRegistryFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton object type regsitry.
+ *
+ * @return $registryInstance A registry for object types
+ */
+ public static final function createObjectTypeRegistryInstance () {
+ // Do we have an instance in the registry?
+ if (Registry::getRegistry()->instanceExists('object_type_registry')) {
+ // Then use this instance
+ $registryInstance = Registry::getRegistry()->getInstance('object_type_registry');
+ } else {
+ // Now prepare the tags instance
+ $registryInstance = self::createObjectByConfiguredName('node_object_type_registry_class');
+
+ // Set the instance in registry for further use
+ Registry::getRegistry()->addInstance('object_type_registry', $registryInstance);
+ }
+
+ // Return the instance
+ return $registryInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for ProtocolResolver
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ProtocolResolverFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) ProtocolResolver instance
+ *
+ * @return $resolverInstance An instance of a ProtocolResolver class
+ */
+ public static final function createResolverFromConfiguredProtocol () {
+ // Get the configured protocol
+ $protocolName = FrameworkConfiguration::getSelfInstance()->getConfigEntry('hub_communication_protocol_type');
+
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists($protocolName . '_protocol_resolver')) {
+ // Get handler from registry
+ $resolverInstance = Registry::getRegistry()->getInstance($protocolName . '_protocol_resolver');
+ } else {
+ // Get the handler instance
+ $resolverInstance = self::createObjectByConfiguredName($protocolName . '_protocol_resolver_class');
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance($protocolName . '_protocol_resolver', $resolverInstance);
+ }
+
+ // Return the instance
+ return $resolverInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for scanners
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ScannerObjectFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) Scanner instance
+ *
+ * @param $taskInstance An instance of a class with an Taskable interface
+ * @return $sourceInstance An instance of a Scanner class
+ */
+ public static final function createScannerInstance (Taskable $taskInstance) {
+ // Get new factory instance
+ $factoryInstance = new ScannerObjectFactory();
+
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Get scanner type for given task instance by searching it in task handler
+ $scannerType = $handlerInstance->searchTask($taskInstance);
+
+ // Only let registered tasks pass
+ assert(!empty($scannerType));
+
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists('scanner_' . $scannerType)) {
+ // Get handler from registry
+ $scannerInstance = Registry::getRegistry()->getInstance('scanner_' . $scannerType);
+ } else {
+ // Get the scanner instance
+ $scannerInstance = ObjectFactory::createObjectByConfiguredName($scannerType);
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('scanner_' . $scannerType, $scannerInstance);
+ }
+
+ // Return the instance
+ return $scannerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A socket factory class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 SocketFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates a valid socket resource from given packae data and protocol
+ *
+ * @param $packageData Raw package data
+ * @param $protocolInstance An instance of a HandleableProtocol class
+ * @return $socketResource Socket resource
+ */
+ public static function createSocketFromPackageData (array $packageData, HandleableProtocol $protocolInstance) {
+ // Get an instance
+ $factoryInstance = new SocketFactory();
+
+ // Construct registry key
+ $registryKey = 'socket_' . $protocolInstance->getProtocolName() . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT];
+
+ // Debug message
+ //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to find a socket with registryKey=' . $registryKey);
+
+ // Is the key there?
+ if (Registry::getRegistry()->instanceExists($registryKey)) {
+ // Get container instance
+ $containerInstance = Registry::getRegistry()->getInstance($registryKey);
+
+ // Get socket back
+ $socketResource = $containerInstance->getSocketResource();
+
+ // Debug message
+ //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Using socket ' . $socketResource . '(' . gettype($socketResource) . ') from registry.');
+ } else {
+ // Construct configuration entry for object factory and get it
+ $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($protocolInstance->getProtocolName() . '_connection_helper_class');
+
+ // Debug message
+ //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Going to use class ' . $className . ' for creating a socket resource ...');
+
+ // And call the static method
+ $socketResource = call_user_func($className . '::createConnectionFromPackageData', $packageData);
+
+ // Debug message
+ //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Created socket ' . $socketResource . '(' . gettype($socketResource) . ') from class ' . $className . '.');
+
+ // Construct container class, this won't be reached if an exception is thrown
+ $containerInstance = self::CreateObjectByConfiguredName('socket_container_class', array($socketResource, NULL, $packageData));
+
+ // Register it with the registry
+ Registry::getRegistry()->addInstance($registryKey, $containerInstance);
+
+ // Debug message
+ //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Socket is now registered in registry.');
+ }
+
+ // Return the resource
+ return $socketResource;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for unit sources
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UnitSourceFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of a configurable and singleton unit source
+ *
+ * @param $unitType Type of the unit source
+ * @return $sourceInstance A UnitSource class instance
+ */
+ public static final function createUnitSourceInstance ($unitType) {
+ // Do we have cache?
+ if (!Registry::getRegistry()->instanceExists($unitType . '_unit_source')) {
+ // Then construct the class' configuraton entry
+ $className = '' . $unitType . '_unit_source_class';
+
+ // Get a class from that configuration entry
+ $sourceInstance = self::createObjectByConfiguredName($className);
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance($unitType . '_unit_source', $sourceInstance);
+ } else {
+ // Get it from registry
+ $sourceInstance = Registry::getRegistry()->getInstance($unitType . '_unit_source');
+ }
+
+ // For any purposes, return the source instance
+ return $sourceInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for URL sources
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 UrlSourceObjectFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) UrlSource instance
+ *
+ * @param $taskInstance An instance of a class with an Taskable interface
+ * @return $sourceInstance An instance of a UrlSource class
+ */
+ public static final function createUrlSourceInstance (Taskable $taskInstance) {
+ // Get new factory instance
+ $factoryInstance = new UrlSourceObjectFactory();
+
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Get source type by looking for given task instance in task handler
+ $sourceType = $handlerInstance->searchTask($taskInstance);
+
+ // Only let registered tasks pass
+ assert(!empty($sourceType));
+
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists('source_' . $sourceType)) {
+ // Get handler from registry
+ $sourceInstance = Registry::getRegistry()->getInstance('source_' . $sourceType);
+ } else {
+ // Get the source instance
+ $sourceInstance = ObjectFactory::createObjectByConfiguredName($sourceType . '_class');
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('source_' . $sourceType, $sourceInstance);
+ }
+
+ // Return the instance
+ return $sourceInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for communicator states
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014, 2015 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 CommunicatorStateFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of a configurable communicator state and sets it in the
+ * given communicator instance.
+ *
+ * @param $stateName Name of the state
+ * @param $communicatorInstance A Communicator class instance
+ * @return $stateInstance A Stateable class instance
+ */
+ public static final function createCommunicatorStateInstanceByName ($stateName, Communicator $communicatorInstance) {
+ // Then construct the class' configuraton entry
+ $className = 'communicator_' . $stateName . '_state_class';
+
+ // Get a class from that configuration entry
+ $stateInstance = self::createObjectByConfiguredName($className, array($communicatorInstance));
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('COMMUNICATOR-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Communicator state has changed from ' . $communicatorInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Once we have that state, set it in the communicator instance
+ $communicatorInstance->setStateInstance($stateInstance);
+
+ // Update communicator data
+ $communicatorInstance->updateCommunicatorData();
+
+ // For any purposes, return the state instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for crawler states
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014, 2015 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 CrawlerStateFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of a configurable crawler state and sets it in the
+ * given crawler instance.
+ *
+ * @param $stateName Name of the state
+ * @return $stateInstance A Stateable class instance
+ */
+ public static final function createCrawlerStateInstanceByName ($stateName) {
+ // Then construct the class' configuraton entry
+ $className = 'crawler_' . $stateName . '_state_class';
+
+ // Get a class from that configuration entry
+ $stateInstance = self::createObjectByConfiguredName($className);
+
+ // Get crawler instance
+ $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Crawler state has changed from ' . $crawlerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Once we have that state, set it in the crawler instance
+ $crawlerInstance->setStateInstance($stateInstance);
+
+ // Update crawler data
+ $crawlerInstance->updateCrawlerData();
+
+ // For any purposes, return the state instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for cruncher states
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherStateFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of a configurable cruncher state and sets it in the
+ * given cruncher instance.
+ *
+ * @param $stateName Name of the state
+ * @param $cruncherInstance A CruncherHelper class instance
+ * @return $stateInstance A Stateable class instance
+ */
+ public static final function createCruncherStateInstanceByName ($stateName) {
+ // Then construct the class' configuraton entry
+ $className = 'cruncher_' . $stateName . '_state_class';
+
+ // Get cruncher instance from registry
+ $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
+
+ // Get a class from that configuration entry
+ $stateInstance = self::createObjectByConfiguredName($className);
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Cruncher state has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Once we have that state, set it in the cruncher instance
+ $cruncherInstance->setStateInstance($stateInstance);
+
+ // For any purposes, return the state instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for DHT states
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtStateFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of a configurable DHT state and sets it in the
+ * given DHT instance.
+ *
+ * @param $stateName Name of the state
+ * @param $dhtInstance A Distributable class instance
+ * @return $stateInstance A Stateable class instance
+ */
+ public static final function createDhtStateInstanceByName ($stateName, Distributable $dhtInstance) {
+ // Then construct the class' configuraton entry
+ $className = 'dht_' . $stateName . '_state_class';
+
+ // Get a class from that configuration entry
+ $stateInstance = self::createObjectByConfiguredName($className, array($dhtInstance));
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: DHT state has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Once we have that state, set it in the DHT instance
+ $dhtInstance->setStateInstance($stateInstance);
+
+ // Update DHT data
+ $dhtInstance->updateDhtData();
+
+ // For any purposes, return the state instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for miner states
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerStateFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of a configurable miner state and sets it in the
+ * given miner instance.
+ *
+ * @param $stateName Name of the state
+ * @return $stateInstance A Stateable class instance
+ */
+ public static final function createMinerStateInstanceByName ($stateName) {
+ // Then construct the class' configuraton entry
+ $className = 'miner_' . $stateName . '_state_class';
+
+ // Get miner instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Get a class from that configuration entry
+ $stateInstance = self::createObjectByConfiguredName($className);
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Miner state has changed from ' . $minerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Once we have that state, set it in the miner instance
+ $minerInstance->setStateInstance($stateInstance);
+
+ // For any purposes, return the state instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for node states
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeStateFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of a configurable node state and sets it in the
+ * given node instance.
+ *
+ * @param $stateName Name of the state
+ * @param $nodeInstance An instance of a NodeHelper class (optional)
+ * @return $stateInstance A Stateable class instance
+ */
+ public static final function createNodeStateInstanceByName ($stateName, NodeHelper $nodeInstance = NULL) {
+ // Then construct the class' configuraton entry
+ $className = 'node_' . $stateName . '_state_class';
+
+ // Is the node instance set?
+ if (is_null($nodeInstance)) {
+ // Get node instance from registry
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+ } // END - if
+
+ // Get a class from that configuration entry
+ $stateInstance = self::createObjectByConfiguredName($className, array($nodeInstance));
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('NODE-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Node state has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Once we have that state, set it in the node instance
+ $nodeInstance->setStateInstance($stateInstance);
+
+ // Update node data
+ $nodeInstance->updateNodeData();
+
+ // For any purposes, return the state instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for peer states
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PeerStateFactory extends ObjectFactory {
+ /**
+ * Static lookup table instance
+ */
+ private static $tableInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Singleton getter for lookup table instances, kept public if we need this
+ * table somewhere else.
+ *
+ * @return $tableInstance An instance of a lookup table
+ */
+ public static final function getTableInstance () {
+ // Is the instance null?
+ if (is_null(self::$tableInstance)) {
+ // Get a new one
+ self::$tableInstance = self::createObjectByConfiguredName('peer_state_lookup_db_wrapper_class');
+ } // END - if
+
+ // Return it
+ return self::$tableInstance;
+ }
+
+ /**
+ * Creates a peer state instance based on errorCode if no entry is found in the lookup table
+ * for the peer given in $packageData 'sender' element or it changes the state if it differs
+ * from current state.
+ *
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @param $packageData Raw package data
+ * @param $socketResource A valid socket resource
+ * @param $errorCode The last error code
+ * @return $stateInstance A Stateable class instance
+ */
+ public static final function createPeerStateInstanceBySocketStatusCode (ConnectionHelper $helperInstance, array $packageData, $socketResource, $errorCode) {
+ // Init state instance, this is better coding practice
+ $stateInstance = NULL;
+
+ // So first we need our lookup table
+ $tableInstance = self::getTableInstance();
+
+ /*
+ * Now try to purge old entries before looking an entry up. This shall
+ * make it sure that only accurate entries can be found.
+ */
+ try {
+ // Purge old entries
+ $tableInstance->purgeOldEntriesBySocketResource($socketResource);
+ } catch (InvalidSocketException $e) {
+ // Just log all errors
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Purging of old entries failed. Message from exception: ' . $e->getMessage());
+ }
+
+ // Do we have an entry?
+ if ($tableInstance->isSenderNewPeer($packageData)) {
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] errorCode=' . $errorCode);
+
+ // Register the new peer with its session id
+ $tableInstance->registerPeerByPackageData($packageData, $socketResource);
+
+ /*
+ * It is a new peer so create the state instance based on error
+ * code and get an instance from it.
+ */
+ $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class');
+
+ // And register it with the lookup table
+ $tableInstance->registerPeerState($stateInstance, $packageData);
+ } elseif ($tableInstance->isSamePeerState($helperInstance, $packageData)) {
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state unchanged, re-generating old state ...');
+
+ /*
+ * The peer's state has noot changed, still we have to return a
+ * state instance, so generate it here.
+ */
+ $stateInstance = self::createPeerStateInstanceByName($helperInstance->getPrintableState(), $helperInstance);
+ } else {
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Updating peer state ...');
+
+ /*
+ * It is an already known peer but with a changed state. So first
+ * get an instance of the state.
+ */
+ $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class');
+
+ // The peer's state has changed, update database now
+ $tableInstance->registerPeerState($stateInstance, $packageData);
+ }
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
+
+ // Set the state in the helper
+ $helperInstance->setStateInstance($stateInstance);
+
+ // For any purposes, return the state instance
+ return $stateInstance;
+ }
+
+ /**
+ * Creates an instance of a configurable peer state and sets it in the
+ * given peer instance.
+ *
+ * @param $stateName Name of the state
+ * @param $helperInstance A ConnectionHelper class instance
+ * @return $stateInstance A Stateable class instance
+ */
+ public static final function createPeerStateInstanceByName ($stateName, ConnectionHelper $helperInstance) {
+ // Get a class from a configuration entry
+ $stateInstance = self::createObjectByConfiguredName('peer_' . $stateName . '_state_class', array($helperInstance));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
+
+ // Once we have that state, set it in the peer instance
+ $helperInstance->setStateInstance($stateInstance);
+
+ // For any purposes, return the state instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for network packages
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageTagsFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * 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.
+ *
+ * @return $packageInstance A network package instance
+ */
+ public static final function createPackageTagsInstance () {
+ // Do we have an instance in the registry?
+ if (Registry::getRegistry()->instanceExists('package_tags')) {
+ // Then use this instance
+ $packageInstance = Registry::getRegistry()->getInstance('package_tags');
+ } else {
+ // Now prepare the tags instance
+ $packageInstance = self::createObjectByConfiguredName('package_tags_class');
+
+ // Set the instance in registry for further use
+ Registry::getRegistry()->addInstance('package_tags', $packageInstance);
+ }
+
+ // Return the instance
+ return $packageInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A HubcoinReward Feature class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 HubcoinRewardFeature extends BaseFeature implements Feature {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this Feature class and prepares it for usage
+ *
+ * @return $featureInstance An instance of this Feature class
+ */
+ public final static function createHubcoinRewardFeature () {
+ // Get a new instance
+ $featureInstance = new HubcoinRewardFeature();
+
+ // Return the prepared instance
+ return $featureInstance;
+ }
+
+ /**
+ * Checks whether this feature can be made available to other classes.
+ *
+ * @return $isAvailable Whether this feature is available
+ */
+ public function isFeatureAvailable () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
+
+ // Testing this feature is pretty simple:
+ $isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === TRUE) && (extension_loaded('scrypt')) && (is_callable('scrypt')));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isAvailable=%d - EXIT!', __METHOD__, __LINE__, intval($isAvailable)));
+
+ // Return status
+ return $isAvailable;
+ }
+
+ /**
+ * Feature method 'generateHash'
+ *
+ * @param $data Data to hash
+ * @return $hash Finished hash
+ */
+ public function featureMethodGenerateHash ($data) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d - CALLED!', __METHOD__, __LINE__, strlen($data)));
+
+ // Make sure the feature is available
+ assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
+
+ // Call inner class
+ $hash = Scrypt::hashScrypt($data);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: hash=%s - EXIT!', __METHOD__, __LINE__, $hash));
+
+ // Return generated hash
+ return $hash;
+ }
+
+ /**
+ * Feature method 'checkHash'
+ *
+ * @param $data Data to check hash for
+ * @param $hash Previously generated hash for valdiation
+ * @return $isValid Whether the given hash matches a new one from given data
+ */
+ public function featureMethodCheckHash ($data, $hash) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
+
+ // Make sure the feature is available
+ assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
+
+ // Determine it
+ $isValid = Scrypt::checkScrypt($data, $hash);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isValid=%d - EXIT!', __METHOD__, __LINE__, intval($isValid)));
+
+ // Return status
+ return $isValid;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for hub activation
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 HubActivation???Filter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createHubActivation???Filter () {
+ // Get a new instance
+ $filterInstance = new HubActivation???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An Announcement filter for hub activation
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeActivationAnnouncementFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeActivationAnnouncementFilter () {
+ // Get a new instance
+ $filterInstance = new NodeActivationAnnouncementFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Prepare a self-test task for the listeners
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_task_class');
+
+ // Register it
+ $handlerInstance->registerTask('announcement', $taskInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Initialization filter for apt-proxy
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyInitializationFilter extends BaseAptProxyFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createAptProxyInitializationFilter () {
+ // Get a new instance
+ $filterInstance = new AptProxyInitializationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get an instance
+ $proxyInstance = ObjectFactory::createObjectByConfiguredName('node_console_apt_proxy_class');
+
+ // Get a registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Set the app instance
+ $proxyInstance->setApplicationInstance($applicationInstance);
+
+ // Add apt-proxy-specific filters
+ $proxyInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
+
+ // Set the apt_proxy instance in registry
+ Registry::getRegistry()->addInstance('apt_proxy', $proxyInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A PhpRequirements filter for apt-proxy
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyPhpRequirementsFilter extends BaseAptProxyFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createAptProxyPhpRequirementsFilter () {
+ // Get a new instance
+ $filterInstance = new AptProxyPhpRequirementsFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If a required PHP function is not available
+ * @todo Add more test and try to add an extra message to the thrown exception
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // By default, the requirement check is passed and zero checks are failed
+ $checkPassed = TRUE;
+ $checksFailed = 0;
+
+ // Socket support is essential...
+ if (!function_exists('socket_create')) {
+ // Test failed
+ $checkPassed = FALSE;
+ $checksFailed++;
+ } // END -if
+
+ // Are all tests passed?
+ if ($checkPassed === FALSE) {
+ // Throw an exception
+ throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A welcome-teaser filter for the apt-proxy
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyWelcomeTeaserFilter extends BaseAptProxyFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createAptProxyWelcomeTeaserFilter () {
+ // Get a new instance
+ $filterInstance = new AptProxyWelcomeTeaserFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ * @todo Handle over the $responseInstance to outputConsoleTeaser()
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
+
+ // Now output the teaser
+ $proxyInstance->outputConsoleTeaser();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for bootstrapping apt-proxy
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Apt-Proxy Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 AptProxyBootstrap???Filter extends BaseAptProxyFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createAptProxyBootstrap???Filter () {
+ // Get a new instance
+ $filterInstance = new AptProxyBootstrap???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get apt-proxy instance
+ $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ExtraBootstrapping filter for bootstrapping apt-proxy
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Apt-Proxy 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 AptProxyBootstrapExtraBootstrappingFilter extends BaseAptProxyFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createAptProxyBootstrapExtraBootstrappingFilter () {
+ // Get a new instance
+ $filterInstance = new AptProxyBootstrapExtraBootstrappingFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $proxyInstance is null (no NullPointerException here)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get apt-proxy instance
+ $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
+
+ // Do some extra bootstrapping steps
+ $proxyInstance->doBootstrapping();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A GenericActivation filter for bootstrapping proxy
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyBootstrapGenericActivationFilter extends BaseAptProxyFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createAptProxyBootstrapGenericActivationFilter () {
+ // Get a new instance
+ $filterInstance = new AptProxyBootstrapGenericActivationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Maybe we want to do somthing more here?
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a apt-proxy instance
+ $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
+
+ // Set the flag
+ $proxyInstance->enableIsActive();
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: apt-proxy has been activated.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for bootstrapping chats
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ChatBootstrap???Filter extends BaseChatFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createChatBootstrap???Filter () {
+ // Get a new instance
+ $filterInstance = new ChatBootstrap???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get chat instance
+ $chatInstance = Registry::getRegistry()->getInstance('chat');
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ExtraBootstrapping filter for bootstrapping chat
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 ChatBootstrapExtraBootstrappingFilter extends BaseChatFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createChatBootstrapExtraBootstrappingFilter () {
+ // Get a new instance
+ $filterInstance = new ChatBootstrapExtraBootstrappingFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $chatInstance is null (no NullPointerException here)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get chat instance
+ $chatInstance = Registry::getRegistry()->getInstance('chat');
+
+ // Do some extra bootstrapping steps
+ $chatInstance->doBootstrapping();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A GenericActivation filter for bootstrapping chat
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 ChatBootstrapGenericActivationFilter extends BaseChatFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createChatBootstrapGenericActivationFilter () {
+ // Get a new instance
+ $filterInstance = new ChatBootstrapGenericActivationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Maybe we want to do somthing more here?
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a chat instance
+ $chatInstance = Registry::getRegistry()->getInstance('chat');
+
+ // Set the flag
+ $chatInstance->enableIsActive();
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: The chat console has been activated.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for bootstrapping crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerBootstrap???Filter extends BaseCrawlerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createCrawlerBootstrap???Filter () {
+ // Get a new instance
+ $filterInstance = new CrawlerBootstrap???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get crawler instance
+ $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ExtraBootstrapping filter for bootstrapping crawler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 CrawlerBootstrapExtraBootstrappingFilter extends BaseCrawlerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCrawlerBootstrapExtraBootstrappingFilter () {
+ // Get a new instance
+ $filterInstance = new CrawlerBootstrapExtraBootstrappingFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $crawlerInstance is null (no NullPointerException here)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get crawler instance
+ $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
+
+ // Do some extra bootstrapping steps
+ $crawlerInstance->doBootstrapping();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A GenericActivation filter for bootstrapping crawler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 CrawlerBootstrapGenericActivationFilter extends BaseCrawlerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createCrawlerBootstrapGenericActivationFilter () {
+ // Get a new instance
+ $filterInstance = new CrawlerBootstrapGenericActivationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Maybe we want to do somthing more here?
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a crawler instance
+ $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
+
+ // Set the flag
+ $crawlerInstance->enableIsActive();
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: The crawler has been activated.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for bootstrapping crunchers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CruncherBootstrap???Filter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createCruncherBootstrap???Filter () {
+ // Get a new instance
+ $filterInstance = new CruncherBootstrap???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get cruncher instance
+ $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A BufferQueue filter for bootstrapping crunchers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherBootstrapBufferQueueInitializerFilter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createCruncherBootstrapBufferQueueInitializerFilter () {
+ // Get a new instance
+ $filterInstance = new CruncherBootstrapBufferQueueInitializerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get cruncher instance
+ $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
+
+ // Init all buffer queues
+ $cruncherInstance->initBufferQueues();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ExtraBootstrapping filter for bootstrapping crunchers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherBootstrapExtraBootstrappingFilter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCruncherBootstrapExtraBootstrappingFilter () {
+ // Get a new instance
+ $filterInstance = new CruncherBootstrapExtraBootstrappingFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $cruncherInstance is null (no NullPointerException here)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get cruncher instance
+ $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
+
+ // Do some extra bootstrapping steps
+ $cruncherInstance->doBootstrapping();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A GenericActivation filter for bootstrapping crunchers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherBootstrapGenericActivationFilter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createCruncherBootstrapGenericActivationFilter () {
+ // Get a new instance
+ $filterInstance = new CruncherBootstrapGenericActivationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Maybe we want to do somthing more here?
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a cruncher instance
+ $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
+
+ // Set the flag
+ $cruncherInstance->enableIsActive();
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: The cruncher has been activated.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for bootstrapping miners
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 MinerBootstrap???Filter extends BaseMinerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createMinerBootstrap???Filter () {
+ // Get a new instance
+ $filterInstance = new MinerBootstrap???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get miner instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A BufferQueue filter for bootstrapping miners
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerBootstrapBufferQueueInitializerFilter extends BaseMinerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createMinerBootstrapBufferQueueInitializerFilter () {
+ // Get a new instance
+ $filterInstance = new MinerBootstrapBufferQueueInitializerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get miner instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Init all buffer queues
+ $minerInstance->initBufferQueues();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ExtraBootstrapping filter for bootstrapping miners
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerBootstrapExtraBootstrappingFilter extends BaseMinerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createMinerBootstrapExtraBootstrappingFilter () {
+ // Get a new instance
+ $filterInstance = new MinerBootstrapExtraBootstrappingFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $minerInstance is null (no NullPointerException here)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get miner instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Do some extra bootstrapping steps
+ $minerInstance->doBootstrapping();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A GenericActivation filter for bootstrapping miners
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerBootstrapGenericActivationFilter extends BaseMinerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createMinerBootstrapGenericActivationFilter () {
+ // Get a new instance
+ $filterInstance = new MinerBootstrapGenericActivationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo Maybe we want to do somthing more here?
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get a miner instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Set the flag
+ $minerInstance->enableIsActive();
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: The miner has been activated.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for bootstrapping
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 NodeBootstrap???Filter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createNodeBootstrap???Filter () {
+ // Get a new instance
+ $filterInstance = new NodeBootstrap???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ExtraBootstrapping filter for bootstrapping
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeBootstrapExtraBootstrappingFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeBootstrapExtraBootstrappingFilter () {
+ // Get a new instance
+ $filterInstance = new NodeBootstrapExtraBootstrappingFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Do some extra bootstrapping steps
+ $nodeInstance->doBootstrapping();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A GenerateNodeId filter for bootstrapping
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node 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 NodeBootstrapGenerateNodeIdFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeBootstrapGenerateNodeIdFilter () {
+ // Get a new instance
+ $filterInstance = new NodeBootstrapGenerateNodeIdFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ /*
+ * Acquire a hub-id. This step generates on first launch a new one and
+ * on any later launches it will restore the hub-id from the database.
+ * A passed 'nickname=xxx' argument will be used to add some
+ * 'personality' to the hub.
+ */
+ $nodeInstance->bootstrapAcquireNodeId($requestInstance, $responseInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A GeneratePrivateKey filter for bootstrapping
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node 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 NodeBootstrapGeneratePrivateKeyFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createNodeBootstrapGeneratePrivateKeyFilter () {
+ // Get a new instance
+ $filterInstance = new NodeBootstrapGeneratePrivateKeyFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ /*
+ * Generate the private key. This will be stored along with the other
+ * node data.
+ */
+ $nodeInstance->bootstrapGeneratePrivateKey();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A GenerateSessionId filter for bootstrapping
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node 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 NodeBootstrapGenerateSessionIdFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeBootstrapGenerateSessionIdFilter () {
+ // Get a new instance
+ $filterInstance = new NodeBootstrapGenerateSessionIdFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ /*
+ * Generate the session id which will only be stored in RAM and kept for
+ * the whole "session".
+ */
+ $nodeInstance->bootstrapGenerateSessionId();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ListenerPool filter for bootstrapping
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node 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 NodeBootstrapListenerPoolFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeBootstrapListenerPoolFilter () {
+ // Get a new instance
+ $filterInstance = new NodeBootstrapListenerPoolFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Now do something
+ $nodeInstance->initializeListenerPool();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Initialization filter for chat
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 ChatInitializationFilter extends BaseChatFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createChatInitializationFilter () {
+ // Get a new instance
+ $filterInstance = new ChatInitializationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get an instance
+ $chatInstance = ObjectFactory::createObjectByConfiguredName('node_console_chat_class');
+
+ // Get a registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Set the app instance
+ $chatInstance->setApplicationInstance($applicationInstance);
+
+ // Add chat-specific filters
+ $chatInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
+
+ // Set the chat instance in registry
+ Registry::getRegistry()->addInstance('chat', $chatInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A PhpRequirements filter for chat
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat Developer Teama
+ * @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 ChatPhpRequirementsFilter extends BaseChatFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createChatPhpRequirementsFilter () {
+ // Get a new instance
+ $filterInstance = new ChatPhpRequirementsFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If a required PHP function is not available
+ * @todo Add more test and try to add an extra message to the thrown exception
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // By default, the requirement check is passed and zero checks are failed
+ $checkPassed = TRUE;
+ $checksFailed = 0;
+
+ // Socket support is essential...
+ if (!function_exists('socket_create')) {
+ // Test failed
+ $checkPassed = FALSE;
+ $checksFailed++;
+ } // END -if
+
+ // Are all tests passed?
+ if ($checkPassed === FALSE) {
+ // Throw an exception
+ throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A welcome-teaser filter for the chat
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 ChatWelcomeTeaserFilter extends BaseChatFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createChatWelcomeTeaserFilter () {
+ // Get a new instance
+ $filterInstance = new ChatWelcomeTeaserFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ * @todo Handle over the $responseInstance to outputConsoleTeaser()
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $chatInstance = Registry::getRegistry()->getInstance('chat');
+
+ // Now output the teaser
+ $chatInstance->outputConsoleTeaser();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? filter for !!!
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Hub!!!???Filter extends BaseHubFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createHub!!!???Filter () {
+ // Get a new instance
+ $filterInstance = new Hub!!!???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A generic filter for apt-proxy sub-project
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 BaseAptProxyFilter extends BaseHubFilter {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real name of class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A generic filter for chat sub-project
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 BaseChatFilter extends BaseHubFilter {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real name of class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A generic filter for crawler sub-project
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 BaseCrawlerFilter extends BaseHubFilter {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real name of class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A generic filter for cruncher sub-project
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 BaseCruncherFilter extends BaseHubFilter {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real name of class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A generic filter for hub project
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubFilter extends BaseFilter {
+ /**
+ * Array with all data XML nodes (which hold the actual data) and their values
+ */
+ protected $dataXmlNodes = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Real name of class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Processes the given raw message content. The method renderXmlContent
+ * may throw (not the method itself) several exceptions:
+ *
+ * InvalidXmlNodeException - If an invalid XML node has been found (e.g.
+ * wrong/out-dated template used)
+ * XmlNodeMismatchException - Again might be caused by invalid XML node
+ * usage
+ * XmlParserException - If the XML message is damaged or not
+ * well-formed
+ *
+ * @param $messageType Type of message
+ * @param $messageData Raw message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @todo Exceptions from renderXmlContent() are currently unhandled
+ */
+ protected function genericProcessMessage ($messageType, array $messageData, Receivable $packageInstance) {
+ // Make sure the wanted element is there
+ assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_MESSAGE]));
+ assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_SENDER]));
+ assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_HASH]));
+ assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_TAGS]));
+
+ // Get a template instance from the factory
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_' . $messageType . '_template_class');
+
+ // Get message content
+ $messageContent = $messageData[NetworkPackage::PACKAGE_CONTENT_MESSAGE];
+
+ // And render the XML content (aka message)
+ $templateInstance->renderXmlContent($messageContent);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: Handling ' . strlen($messageContent) . ' bytes: ' . $messageContent);
+
+ /*
+ * The template system now stores all required data as 'general'
+ * variables, so simply get them. If there is an invalid XML node
+ * inside the message, the above method call will cause exceptions.
+ */
+ foreach ($this->dataXmlNodes as $key => $dummy) {
+ // Call it
+ $value = $templateInstance->readXmlData($key);
+
+ /*
+ * If value is NULL, a variable hasn't been found. This could mean
+ * that *this* node is running an out-dated software or the other
+ * peer is using an out-dated $messageType.xml template.
+ */
+ if (is_null($value)) {
+ // Output a warning
+ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: Found not fully supported variable ' . $key . ' - skipping.');
+
+ // Skip this part, don't write NULLs to the array
+ continue;
+ } // END - if
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: key=' . $key . ',value=' . $value);
+
+ // Set it now
+ $this->dataXmlNodes[$key] = $value;
+ } // END - foreach
+
+ // Construct an array for pushing it on next stack
+ $messageArray = array(
+ // Message data itself
+ NetworkPackage::MESSAGE_ARRAY_DATA => $this->dataXmlNodes,
+ // Message type (which is $messageType)
+ NetworkPackage::MESSAGE_ARRAY_TYPE => $messageType,
+ // Message sender
+ NetworkPackage::MESSAGE_ARRAY_SENDER => $messageData[NetworkPackage::PACKAGE_CONTENT_SENDER],
+ // Package hash
+ NetworkPackage::MESSAGE_ARRAY_HASH => $messageData[NetworkPackage::PACKAGE_CONTENT_HASH],
+ // Package tags
+ NetworkPackage::MESSAGE_ARRAY_TAGS => $messageData[NetworkPackage::PACKAGE_CONTENT_TAGS],
+ );
+
+ // Push the processed message back on stack
+ $packageInstance->getStackInstance()->pushNamed(NetworkPackage::STACKER_NAME_PROCESSED_MESSAGE, $messageArray);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A generic filter for miner sub-project
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 BaseMinerFilter extends BaseHubFilter {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real name of class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A generic filter for nodes
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseNodeFilter extends BaseHubFilter {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real name of class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Initialization filter for crawler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 CrawlerInitializationFilter extends BaseCrawlerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCrawlerInitializationFilter () {
+ // Get a new instance
+ $filterInstance = new CrawlerInitializationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get an instance
+ $crawlerInstance = ObjectFactory::createObjectByConfiguredName('node_console_crawler_class');
+
+ // Get a registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Set the app instance
+ $crawlerInstance->setApplicationInstance($applicationInstance);
+
+ // Add crawler-specific filters
+ $crawlerInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A PhpRequirements filter for crawler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Teama
+ * @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 CrawlerPhpRequirementsFilter extends BaseCrawlerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCrawlerPhpRequirementsFilter () {
+ // Get a new instance
+ $filterInstance = new CrawlerPhpRequirementsFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If a required PHP function is not available
+ * @todo Add more test and try to add an extra message to the thrown exception
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // By default, the requirement check is passed and zero checks are failed
+ $checkPassed = TRUE;
+ $checksFailed = 0;
+
+ // Socket support is essential...
+ if (!function_exists('socket_create')) {
+ // Test failed
+ $checkPassed = FALSE;
+ $checksFailed++;
+ } // END -if
+
+ // Are all tests passed?
+ if ($checkPassed === FALSE) {
+ // Throw an exception
+ throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A welcome-teaser filter for the crawler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 CrawlerWelcomeTeaserFilter extends BaseCrawlerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCrawlerWelcomeTeaserFilter () {
+ // Get a new instance
+ $filterInstance = new CrawlerWelcomeTeaserFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ * @todo Handle over the $responseInstance to outputConsoleTeaser()
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
+
+ // Now output the teaser
+ $crawlerInstance->outputConsoleTeaser();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for crunchers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Cruncher???Filter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createCruncher???Filter () {
+ // Get a new instance
+ $filterInstance = new Cruncher???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Implement this!
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A Initialization filter for crunchers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherInitializationFilter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCruncherInitializationFilter () {
+ // Get a new instance
+ $filterInstance = new CruncherInitializationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // The default cruncher-mode is from our configuration
+ $cruncherMode = $this->getConfigInstance()->getConfigEntry('cruncher_default_mode');
+
+ // Is the cruncher 'mode' parameter set?
+ if ($requestInstance->isRequestElementSet('mode')) {
+ // Then use this which overrides the config entry temporarily
+ $cruncherMode = $requestInstance->getRequestElement('mode');
+ } else {
+ // Set it for easier re-usage
+ $requestInstance->setRequestElement('mode', $cruncherMode);
+ }
+
+ // Now convert the cruncher-mode in a class name
+ $className = 'Hub' . self::convertToClassName($cruncherMode) . 'Cruncher';
+
+ // And try to instance it
+ try {
+ // Get an instance
+ $cruncherInstance = ObjectFactory::createObjectByName($className);
+
+ // Get a registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Set the app instance
+ $cruncherInstance->setApplicationInstance($applicationInstance);
+
+ // Add cruncher-specific filters
+ $cruncherInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
+ } catch (ClassNotFoundException $e) {
+ // This exception means, the cruncher mode is invalid.
+ // @TODO Can we rewrite this to app_exit() ?
+ $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: cruncher mode ' . $cruncherMode . ' is invalid.');
+ }
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A PhpRequirements filter for crunchers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherPhpRequirementsFilter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCruncherPhpRequirementsFilter () {
+ // Get a new instance
+ $filterInstance = new CruncherPhpRequirementsFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If a required PHP function is not available
+ * @todo Add more test and try to add an extra message to the thrown exception
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // By default, the requirement check is passed and zero checks are failed
+ $checkPassed = TRUE;
+ $checksFailed = 0;
+
+ // Socket support is essential...
+ if (!function_exists('socket_create')) {
+ // Test failed
+ $checkPassed = FALSE;
+ $checksFailed++;
+ } // END -if
+
+ // Are all tests passed?
+ if ($checkPassed === FALSE) {
+ // Throw an exception
+ throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A welcome-teaser filter for the cruncher
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherWelcomeTeaserFilter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCruncherWelcomeTeaserFilter () {
+ // Get a new instance
+ $filterInstance = new CruncherWelcomeTeaserFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ * @todo Handle over the $responseInstance to outputConsoleTeaser()
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
+
+ // Now output the teaser
+ $cruncherInstance->outputConsoleTeaser();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for miners
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Miner???Filter extends BaseminerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createMiner???Filter () {
+ // Get a new instance
+ $filterInstance = new Miner???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Implement this!
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A Initialization filter for miners
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerInitializationFilter extends BaseMinerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createMinerInitializationFilter () {
+ // Get a new instance
+ $filterInstance = new MinerInitializationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // The default miner-mode is from our configuration
+ $minerMode = $this->getConfigInstance()->getConfigEntry('miner_default_mode');
+
+ // Is the miner 'mode' parameter set?
+ if ($requestInstance->isRequestElementSet('mode')) {
+ // Then use this which overrides the config entry temporarily
+ $minerMode = $requestInstance->getRequestElement('mode');
+ } else {
+ // Set it for easier re-usage
+ $requestInstance->setRequestElement('mode', $minerMode);
+ }
+
+ // Now convert the miner-mode in a class name
+ $className = 'Hub' . self::convertToClassName($minerMode) . 'Miner';
+
+ // And try to instance it
+ try {
+ // Get an instance
+ $minerInstance = ObjectFactory::createObjectByName($className);
+
+ // Get a registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Set the app instance
+ $minerInstance->setApplicationInstance($applicationInstance);
+
+ // Add miner-specific filters
+ $minerInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
+ } catch (ClassNotFoundException $e) {
+ // This exception means, the miner mode is invalid.
+ // @TODO Can we rewrite this to app_exit() ?
+ $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: miner mode ' . $minerMode . ' is invalid.');
+ }
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A PhpRequirements filter for miners
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerPhpRequirementsFilter extends BaseMinerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createMinerPhpRequirementsFilter () {
+ // Get a new instance
+ $filterInstance = new MinerPhpRequirementsFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If a required PHP function is not available
+ * @todo Add more test and try to add an extra message to the thrown exception
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // By default, the requirement check is passed and zero checks are failed
+ $checkPassed = TRUE;
+ $checksFailed = 0;
+
+ // Socket support is essential...
+ if (!function_exists('socket_create')) {
+ // Test failed
+ $checkPassed = FALSE;
+ $checksFailed++;
+ } // END -if
+
+ // If scrypt() is not found (ext-scrypt) then the "Hubcoins reward" is not working
+ if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) {
+ // Mark it as working
+ self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature possible.');
+ $this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE);
+ } else {
+ // Not working (not all have ext-scrypt installed
+ self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
+ }
+
+ // Are all tests passed?
+ if ($checkPassed === FALSE) {
+ // Throw an exception
+ throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A welcome-teaser filter for the miner
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerWelcomeTeaserFilter extends BaseMinerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createMinerWelcomeTeaserFilter () {
+ // Get a new instance
+ $filterInstance = new MinerWelcomeTeaserFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ * @todo Handle over the $responseInstance to outputConsoleTeaser()
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Now output the teaser
+ $minerInstance->outputConsoleTeaser();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for nodes
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Node???Filter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createNode???Filter () {
+ // Get a new instance
+ $filterInstance = new Node???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Implement this!
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A Initialization filter for nodes
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeInitializationFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeInitializationFilter () {
+ // Get a new instance
+ $filterInstance = new NodeInitializationFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Try to instance it by using a factory
+ try {
+ // Get an instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance($requestInstance, $responseInstance);
+ } catch (ClassNotFoundException $e) {
+ // This exception means, the node mode is invalid.
+ // @TODO Can we rewrite this to app_exit() ?
+ $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: node mode ' . $nodeMode . ' is invalid.');
+ }
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE-INIT-FILTER[' . __METHOD__ . ':' . __LINE__ . ']: Node ' . $nodeMode . ' has been added to registry.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A PhpRequirements filter for nodes
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodePhpRequirementsFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodePhpRequirementsFilter () {
+ // Get a new instance
+ $filterInstance = new NodePhpRequirementsFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If a required PHP function is not available
+ * @todo Add more test and try to add an extra message to the thrown exception
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // By default, the requirement check is passed and zero checks are failed
+ $checkPassed = TRUE;
+ $checksFailed = 0;
+
+ // Socket support is essential...
+ if (!function_exists('socket_create')) {
+ // Test failed
+ $checkPassed = FALSE;
+ $checksFailed++;
+ } // END - if
+
+ // If scrypt() is not found (ext-scrypt) then the "Hubcoins reward" is not working
+ if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) {
+ // Mark it as working
+ self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature possible.');
+ $this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE);
+ } else {
+ // Not working (not all have ext-scrypt installed
+ self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
+ }
+
+ // Are all tests passed?
+ if ($checkPassed === FALSE) {
+ // Throw an exception
+ throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A welcome-teaser filter for the console
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeWelcomeTeaserFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeWelcomeTeaserFilter () {
+ // Get a new instance
+ $filterInstance = new NodeWelcomeTeaserFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ * @todo Handle over the $responseInstance to outputConsoleTeaser()
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Now output the teaser
+ $nodeInstance->outputConsoleTeaser();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A shutdown filter for shutting down the apt-proxy. This filter should be the
+ * last one in 'shutdown' chain so the apt-proxy is shutted down at the very
+ * end of its life...
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyShutdownFilter extends BaseAptProxyFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createAptProxyShutdownFilter () {
+ // Get a new instance
+ $filterInstance = new AptProxyShutdownFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
+
+ // Shutdown the apt-proxy. This should be the last line
+ $proxyInstance->doShutdown();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A shutdown filter for shutting down the chat console. This filter should be
+ * the last one in 'shutdown' chain so the chat is shutted down at the very end
+ * of its life...
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 ChatShutdownFilter extends BaseChatFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createChatShutdownFilter () {
+ // Get a new instance
+ $filterInstance = new ChatShutdownFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $chatInstance = Registry::getRegistry()->getInstance('chat');
+
+ // Shutdown the chat. This should be the last line
+ $chatInstance->doShutdown();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A shutdown filter for shutting down the crawler. This filter should be the
+ * last one in 'shutdown' chain so the crawler is shutted down at the very end
+ * of its life...
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 CrawlerShutdownFilter extends BaseCrawlerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCrawlerShutdownFilter () {
+ // Get a new instance
+ $filterInstance = new CrawlerShutdownFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
+
+ // Shutdown the crawler. This should be the last line
+ $crawlerInstance->doShutdown();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A shutdown filter for shutting down the cruncher. This filter should be the
+ * last one in 'shutdown' chain so the hub is shutted down at the very end of
+ * its life... R.I.P. little cruncher...
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherShutdownFilter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCruncherShutdownFilter () {
+ // Get a new instance
+ $filterInstance = new CruncherShutdownFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
+
+ // Shutdown the cruncher. This should be the last line
+ $cruncherInstance->doShutdown();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A shutdown filter for shutting down the miner. This filter should be the
+ * last one in 'shutdown' chain so the hub is shutted down at the very end of
+ * its life... R.I.P. little miner...
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerShutdownFilter extends BaseMinerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createMinerShutdownFilter () {
+ // Get a new instance
+ $filterInstance = new MinerShutdownFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Shutdown the miner. This should be the last line
+ $minerInstance->doShutdown();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for shutting down the node.
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 HubShutdown???Filter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createHubShutdown???Filter () {
+ // Get a new instance
+ $filterInstance = new HubShutdown???Filter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A FlushNodeList filter for shutting down the node.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeShutdownFlushNodeListFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeShutdownFlushNodeListFilter () {
+ // Get a new instance
+ $filterInstance = new NodeShutdownFlushNodeListFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Now do something
+ $this->partialStub('Please implement this step.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ShutdownNode filter for shutting down the node. This filter should be the
+ * last one in 'shutdown' chain so the hub is shutted down at the very end of
+ * its life... R.I.P. little hub...
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeShutdownNodeFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeShutdownNodeFilter () {
+ // Get a new instance
+ $filterInstance = new NodeShutdownNodeFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Shutdown the node. This should be the last line
+ $nodeInstance->doShutdown();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A TaskHandler filter for shutting down the node.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeShutdownTaskHandlerFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeShutdownTaskHandlerFilter () {
+ // Get a new instance
+ $filterInstance = new NodeShutdownTaskHandlerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Shutdown the task manager and all its registered tasks
+ $handlerInstance->doShutdown();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A AnnouncementAnswerTag filter for Package
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageAnnouncementAnswerTagFilter extends BaseNodeFilter implements FilterablePackage {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->dataXmlNodes = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => '',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => '',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID => '',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '',
+ BaseXmlAnswerTemplateEngine::ANSWER_STATUS => '',
+ );
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createPackageAnnouncementAnswerTagFilter () {
+ // Get a new instance
+ $filterInstance = new PackageAnnouncementAnswerTagFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Processes the given raw message content. The method renderXmlContent
+ * may throw (not the method itself) several exceptions:
+ *
+ * @param $messageData Raw message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function processMessage (array $messageData, Receivable $packageInstance) {
+ // Process message in generic way
+ $this->genericProcessMessage('announcement_answer', $messageData, $packageInstance);
+ }
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A DhtBootstrapAnswerTag filter for Package
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageDhtBootstrapAnswerTagFilter extends BaseNodeFilter implements FilterablePackage {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->dataXmlNodes = array(
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => '',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_LIST => '',
+ BaseXmlAnswerTemplateEngine::ANSWER_STATUS => '',
+ );
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createPackageDhtBootstrapAnswerTagFilter () {
+ // Get a new instance
+ $filterInstance = new PackageDhtBootstrapAnswerTagFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Processes the given raw message content. The method renderXmlContent
+ * may throw (not the method itself) several exceptions:
+ *
+ * @param $messageData Raw message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function processMessage (array $messageData, Receivable $packageInstance) {
+ // Process message in generic way
+ $this->genericProcessMessage('dht_bootstrap_answer', $messageData, $packageInstance);
+ }
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A RequestNodeListAnswerTag filter for Package
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageRequestNodeListAnswerTagFilter extends BaseNodeFilter implements FilterablePackage {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->dataXmlNodes = array(
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID => '',
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST => '',
+ BaseXmlAnswerTemplateEngine::ANSWER_STATUS => '',
+ );
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createPackageRequestNodeListAnswerTagFilter () {
+ // Get a new instance
+ $filterInstance = new PackageRequestNodeListAnswerTagFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Processes the given raw message content. The method renderXmlContent
+ * may throw (not the method itself) several exceptions:
+ *
+ * @param $messageData Raw message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function processMessage (array $messageData, Receivable $packageInstance) {
+ // Process message in generic way
+ $this->genericProcessMessage('request_node_list_answer', $messageData, $packageInstance);
+ }
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A AnnouncementTag filter for packages
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageAnnouncementTagFilter extends BaseNodeFilter implements FilterablePackage {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->dataXmlNodes = array(
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => '',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => '',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE => '',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID => '',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => '',
+ );
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createPackageAnnouncementTagFilter () {
+ // Get a new instance
+ $filterInstance = new PackageAnnouncementTagFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Processes the given raw message content. The method renderXmlContent
+ * may throw (not the method itself) several exceptions:
+ *
+ * InvalidXmlNodeException - If an invalid XML node has been found (e.g.
+ * wrong/out-dated template used)
+ * XmlNodeMismatchException - Again might be caused by invalid XML node
+ * usage
+ * XmlParserException - If the XML message is damaged or not
+ * well-formed
+ *
+ * @param $messageData Raw message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function processMessage (array $messageData, Receivable $packageInstance) {
+ // Process message generic
+ $this->genericProcessMessage('announcement', $messageData, $packageInstance);
+ }
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A DhtBootstrapTag filter for packages
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageDhtBootstrapTagFilter extends BaseNodeFilter implements FilterablePackage {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->dataXmlNodes = array(
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => '',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => '',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => '',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE => '',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => '',
+ );
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createPackageDhtBootstrapTagFilter () {
+ // Get a new instance
+ $filterInstance = new PackageDhtBootstrapTagFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Processes the given raw message content. The method renderXmlContent
+ * may throw (not the method itself) several exceptions:
+ *
+ * InvalidXmlNodeException - If an invalid XML node has been found (e.g.
+ * wrong/out-dated template used)
+ * XmlNodeMismatchException - Again might be caused by invalid XML node
+ * usage
+ * XmlParserException - If the XML message is damaged or not
+ * well-formed
+ *
+ * @param $messageData Raw message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function processMessage (array $messageData, Receivable $packageInstance) {
+ // Process message generic
+ $this->genericProcessMessage('dht_bootstrap', $messageData, $packageInstance);
+ }
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A RequestNodeListTag filter for packages
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageRequestNodeListTagFilter extends BaseNodeFilter implements FilterablePackage {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init XML nodes array which contains the required data
+ $this->dataXmlNodes = array(
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES => '',
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => '',
+ );
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createPackageRequestNodeListTagFilter () {
+ // Get a new instance
+ $filterInstance = new PackageRequestNodeListTagFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Processes the given raw message content.
+ *
+ * @param $messageData Raw message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function processMessage (array $messageData, Receivable $packageInstance) {
+ // Process messasge generic
+ $this->genericProcessMessage('request_node_list', $messageData, $packageInstance);
+ }
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A SelfConnectTag filter for packages
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageSelfConnectTagFilter extends BaseNodeFilter implements FilterablePackage {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->dataXmlNodes = array(
+ XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID => '',
+ XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID => '',
+ );
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createPackageSelfConnectTagFilter () {
+ // Get a new instance
+ $filterInstance = new PackageSelfConnectTagFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Processes the given raw message content. The method renderXmlContent
+ * may throw (not the method itself) several exceptions:
+ *
+ * InvalidXmlNodeException - If an invalid XML node has been found (e.g.
+ * wrong/out-dated template used)
+ * XmlNodeMismatchException - Again might be caused by invalid XML node
+ * usage
+ * XmlParserException - If the XML message is damaged or not
+ * well-formed
+ *
+ * @param $messageData Raw message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function processMessage (array $messageData, Receivable $packageInstance) {
+ // Process generic
+ $this->genericProcessMessage('self_connect', $messageData, $packageInstance);
+ }
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TaskHandlerInitializer filter for apt-proxy
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 apt-proxy 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 AptProxyTaskHandlerInitializerFilter extends BaseAptProxyFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createAptProxyTaskHandlerInitializerFilter () {
+ // Get a new instance
+ $filterInstance = new AptProxyTaskHandlerInitializerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If the filter chain needs to be interrupted
+ * @todo 5% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get apt-proxy instance
+ //$chatInstance = Registry::getRegistry()->getInstance('chat');
+
+ // Get a new task handler instance
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
+
+ // Put the task handler in registry
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
+
+ /*
+ * Register all tasks:
+ *
+ * 1) apt-proxy listener
+ */
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('apt_proxy_listener_task_class');
+ $handlerInstance->registerTask('apt_proxy_listener', $taskInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TaskHandlerInitializer filter for chat
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 ChatTaskHandlerInitializerFilter extends BaseChatFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createChatTaskHandlerInitializerFilter () {
+ // Get a new instance
+ $filterInstance = new ChatTaskHandlerInitializerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If the filter chain needs to be interrupted
+ * @todo 5% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get chat instance
+ //$chatInstance = Registry::getRegistry()->getInstance('chat');
+
+ // Get a new task handler instance
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
+
+ // Put the task handler in registry
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
+
+ /*
+ * Register all tasks:
+ *
+ * 1) Telnet session listener
+ */
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('chat_telnet_listener_task_class');
+ $handlerInstance->registerTask('chat_telnet_listener', $taskInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TaskHandlerInitializer filter for crawler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 CrawlerTaskHandlerInitializerFilter extends BaseCrawlerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCrawlerTaskHandlerInitializerFilter () {
+ // Get a new instance
+ $filterInstance = new CrawlerTaskHandlerInitializerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If the filter chain needs to be interrupted
+ * @todo 10% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get crawler instance
+ //$crawlerInstance = Registry::getRegistry()->getInstance('crawler');
+
+ // Get a new task handler instance
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
+
+ // Put the task handler in registry
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
+
+ /*
+ * Register all tasks:
+ *
+ * 1) "Communicator" for crawler->node communication
+ */
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_node_communicator_task_class');
+ $handlerInstance->registerTask('crawler_node_communicator', $taskInstance);
+
+ // 2) Local URL crawler (gets URLs locally and adds them to the analyzer's input stack)
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_local_url_crawler_task_class');
+ $handlerInstance->registerTask('crawler_local_url_crawler', $taskInstance);
+
+ // 3) Remote URL crawler (gets URLs locally for other nodes, also includes the crawled URL in local index)
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_remote_url_crawler_task_class');
+ $handlerInstance->registerTask('crawler_remote_url_crawler', $taskInstance);
+
+ // 4) Remote-crawl publisher (publishes crawl jobs for remote retrieval)
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_remote_job_publisher_task_class');
+ $handlerInstance->registerTask('crawler_remote_job_publisher', $taskInstance);
+
+ // 5) MIME sniffer
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_mime_sniffer_task_class');
+ $handlerInstance->registerTask('crawler_mime_sniffer', $taskInstance);
+
+ // 6) Document parser (converts document to meta format)
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_document_parser_task_class');
+ $handlerInstance->registerTask('crawler_document_parser', $taskInstance);
+
+ // 7) Document structure analyzer
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_structure_analyzer_task_class');
+ $handlerInstance->registerTask('crawler_structure_analyzer', $taskInstance);
+
+ // 8) Snippet extractor
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_snippet_extractor_task_class');
+ $handlerInstance->registerTask('crawler_snippet_extractor', $taskInstance);
+
+ // 9) Node ping
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_ping_task_class');
+ $handlerInstance->registerTask('crawler_ping', $taskInstance);
+
+ // 10) URL sources
+ foreach (explode(':', $this->getConfigInstance()->getConfigEntry('crawler_url_stacks')) as $stack) {
+ // Init task instance
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_url_source_' . $stack . '_task_class');
+
+ // And register it
+ $handlerInstance->registerTask('crawler_url_source_' . $stack, $taskInstance);
+ } // END - foreach
+
+ // 11) Uploaded list scanner (checks for wanted files)
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_uploaded_list_scanner_task_class');
+ $handlerInstance->registerTask('crawler_uploaded_list_scanner', $taskInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TaskHandlerInitializer filter for crunchers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherTaskHandlerInitializerFilter extends BaseCruncherFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createCruncherTaskHandlerInitializerFilter () {
+ // Get a new instance
+ $filterInstance = new CruncherTaskHandlerInitializerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If the filter chain needs to be interrupted
+ * @todo 5% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get cruncher instance
+ //$cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
+
+ // Get a new task handler instance
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
+
+ // Put the task handler in registry
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
+
+ // Register all tasks:
+ //
+ // 1) A task for fetching WUs (work units) or test units
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('cruncher_work_unit_fetcher_task_class');
+ $handlerInstance->registerTask('cruncher_work_unit_fetcher', $taskInstance);
+
+ /*
+ * 2) A task for generating test units, a if() block could be placed
+ * around this but that would make this method look a little ugly and
+ * even more when more "temporary" tasks should be registered.
+ */
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_producer_task_class');
+ $handlerInstance->registerTask('cruncher_test_unit_producer', $taskInstance);
+
+ /*
+ * 3) A task for generating keys based on the generated test unit. This
+ * task will only be executed if the state of the cruncher is one of
+ * these: 'virgin'.
+ */
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('cruncher_key_producer_task_class');
+ $handlerInstance->registerTask('cruncher_key_producer', $taskInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TaskHandlerInitializer filter for miners
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerTaskHandlerInitializerFilter extends BaseMinerFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createMinerTaskHandlerInitializerFilter () {
+ // Get a new instance
+ $filterInstance = new MinerTaskHandlerInitializerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If the filter chain needs to be interrupted
+ * @todo 5% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get miner instance
+ //$minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Get a new task handler instance
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
+
+ // Put the task handler in registry
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
+
+ // Register all tasks:
+ //
+ // 1) A task for fetching blocks from the network
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_block_fetcher_task_class');
+ $handlerInstance->registerTask('miner_block_fetcher', $taskInstance);
+
+ /*
+ * 2) A task for generating a test "genesis" block. This "block"
+ * consists of several hashes of famous phrases or "catch lines" from
+ * free-software authors.
+ */
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_test_genesis_block_producer_task_class');
+ $handlerInstance->registerTask('miner_test_genesis_block_producer', $taskInstance);
+
+ /*
+ * 3) A task for generating a real "genesis" block. @TODO Define how a
+ * real "genesis" block is generated
+ */
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_real_genesis_block_producer_task_class');
+ $handlerInstance->registerTask('miner_real_genesis_block_producer', $taskInstance);
+
+ /*
+ * 4) A task for communicating into the locally running 'hub' node.
+ * This rask will check for new blocks on the mining network and
+ * tries to claim found blocks.
+ */
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_node_communicator_task_class');
+ $handlerInstance->registerTask('miner_node_communicator', $taskInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TaskHandlerInitializer filter for hubs
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeTaskHandlerInitializerFilter extends BaseNodeFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public static final function createNodeTaskHandlerInitializerFilter () {
+ // Get a new instance
+ $filterInstance = new NodeTaskHandlerInitializerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If the filter chain needs to be interrupted
+ * @todo Maybe some more tasks needs to be added?
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Get a new task handler instance
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
+
+ // Put the task handler in registry
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
+
+ // Prepare a package-tags initialization task for the listeners
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_package_tags_init_task_class');
+
+ // Register it
+ $handlerInstance->registerTask('package_tags_init', $taskInstance);
+
+ // Generate package writer task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_package_writer_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('network_package_writer', $taskInstance);
+
+ // Generate package reader task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_package_reader_task_class');
+
+ // Network package reader, needs to be delayed a little
+ $handlerInstance->registerTask('network_package_reader', $taskInstance);
+
+ // Generate socket listener task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_socket_listener_task_class');
+
+ // Network package reader, needs to be delayed a little
+ $handlerInstance->registerTask('socket_listener', $taskInstance);
+
+ // Generate package decoder task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_package_decoder_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('package_decoder', $taskInstance);
+
+ // Generate chunk assembler task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_chunk_assembler_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('chunk_assembler', $taskInstance);
+
+ // Generate DHT initialization task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_init_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('dht_init', $taskInstance);
+
+ // Generate DHT query task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_query_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('dht_query', $taskInstance);
+
+ // Generate DHT publication-check task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_publication_check_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('dht_check_publication', $taskInstance);
+
+ // Generate DHT publication task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_publication_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('dht_publication', $taskInstance);
+
+ // Prepare a self-test task for the listeners
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_selfconnect_task_class');
+
+ // Register it
+ $handlerInstance->registerTask('self_connect', $taskInstance);
+
+ // Prepare a update-check task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_update_check_task_class');
+
+ // Register it
+ $handlerInstance->registerTask('update_check', $taskInstance);
+
+ // Get the list instance here
+ $listInstance = $nodeInstance->getListenerPoolInstance()->getPoolEntriesInstance();
+
+ // Prepare a ping task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_ping_task_class', array($listInstance));
+
+ // Register it
+ $handlerInstance->registerTask('ping', $taskInstance);
+
+ /*
+ * Allow extra node-depending tasks, e.g. the bootstrapper node needs
+ * booting its DHT. DHTs are decentralized and are working on
+ * peer-to-peer basis.
+ */
+ $nodeInstance->addExtraTasks($handlerInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A AnnouncementAnswerOkay handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->searchData = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ );
+
+ // Set handler name
+ $this->setHandlerName('announcement_answer_okay');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createAnnouncementAnswerOkayHandler () {
+ // Get new instance
+ $handlerInstance = new AnnouncementAnswerOkayHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles given message data array
+ *
+ * @param $messageData An array of message data
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @todo Do some more here: Handle karma, et cetera?
+ */
+ public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
+ /*
+ * Query DHT and force update (which will throw an exception if the
+ * node is not found).
+ */
+ $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
+
+ // Get handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Generate DHT bootstrap task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
+
+ // Get the node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Change state
+ $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
+
+ // Prepare next message
+ $this->prepareNextMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * The following array is being handled over:
+ *
+ * my-external-address => 1.2.3.4
+ * my-internal-address => 5.6.7.8
+ * my-status => reachable
+ * my-node-id => aaabbbcccdddeeefff123456789
+ * my-session-id => aaabbbcccdddeeefff123456789
+ * my-tcp-port => 9060
+ * my-udp-port => 9060
+ * answer-status => OKAY
+ * message_type => announcement_answer
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Get an array of all accepted object types
+ $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
+
+ // Add missing (temporary) configuration 'accepted_object_types'
+ $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration. For content of $messageData see method comment above.
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Remove temporay configuration
+ $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Handler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('|||_answer_===');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function create???Handler () {
+ // Get new instance
+ $handlerInstance = new ???Handler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles given message data array
+ *
+ * @param $messageData An array of message data
+ * @return void
+ */
+ public function handleAnswerMessageData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general answer-status handler. So called "answer-status handler" are
+ * classes which handles a message field 'answer-status' which is, alongside
+ * many other node-relevant data, the main part of the answer message. These
+ * answer messages, by the way, are never sent unrequested. This, however,
+ * sounds logical because the answer is a reply from a node that has responded
+ * on a message.
+ *
+ * The answer-status field gives information back to the requesting node if the
+ * receiving node could handle the message properly (all verfication steps are
+ * passed, message type was understood, correct receiver, et cetera) and how
+ * it handles it. Some messages may be rejected, e.g. when the requesting node
+ * is blacklisted or its behavour has changed.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
+ */
+abstract class BaseAnserStatusHandler extends BaseDataHandler {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A RequestNodeListAnswerOkay handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->searchData = array(
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
+ );
+
+ // Set handler name
+ $this->setHandlerName('request_node_list_answer_okay');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createRequestNodeListAnswerOkayHandler () {
+ // Get new instance
+ $handlerInstance = new RequestNodeListAnswerOkayHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles given message data array
+ *
+ * @param $messageData An array of message data
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws NodeSessionIdVerficationException If the provided session id is not matching
+ * @todo Do some more here: Handle karma, et cetera?
+ */
+ public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
+ // Make sure node-list is found in array
+ assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
+
+ // Save node list
+ $nodeList = json_decode(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
+
+ // Make sure it is completely decoded
+ assert(is_array($nodeList));
+
+ // ... and remove it as it should not be included now
+ unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
+
+ // Write node list to DHT
+ $this->getDhtInstance()->insertNodeList($nodeList);
+
+ /*
+ * Query DHT and force update (which will throw an exception if the
+ * node is not found).
+ */
+ $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
+
+ // Prepare next message ("hello" message to all returned nodes)
+ //$this->prepareNextMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * The following array is being handled over:
+ *
+ * session-id => aaabbbcccdddeeefff123456789
+ * node-list => aabb:ccdd:eeff
+ * answer-status => OKAY
+ * message_type => request_node_list_answer
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @todo 0% done
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration. For content of $messageData see method comment above.
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @todo 0% done
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Chunk handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ChunkHandler extends BaseHandler implements HandleableChunks, Registerable {
+ /**
+ * Stacker for chunks with final EOP
+ */
+ const STACKER_NAME_CHUNKS_WITH_FINAL_EOP = 'final_chunks';
+ const STACKER_NAME_CHUNKS_WITHOUT_FINAL = 'pending_chunks';
+ const STACKER_NAME_ASSEMBLED_RAW_DATA = 'chunk_raw_data';
+
+ /**
+ * Chunk splits:
+ * 0 = Hash
+ * 1 = Serial number
+ * 2 = Raw data
+ */
+ const CHUNK_SPLITS_INDEX_HASH = 0;
+ const CHUNK_SPLITS_INDEX_SERIAL = 1;
+ const CHUNK_SPLITS_INDEX_RAW_DATA = 2;
+
+ /**
+ * The final array for assembling the original package back together
+ */
+ private $finalPackageChunks = array();
+
+ /**
+ * Array of chunk hashes
+ */
+ private $chunkHashes = array();
+
+ /**
+ * Raw EOP chunk data in an array:
+ *
+ * 0 = Final hash,
+ * 1 = Hash of last chunk
+ */
+ private $eopChunk = array();
+
+ /**
+ * Raw package data
+ */
+ private $rawPackageData = '';
+
+ /**
+ * Fragmenter instance, needs to be set here again
+ */
+ private $fragmenterInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('chunk');
+
+ // Initialize handler
+ $this->initHandler();
+
+ // Get a fragmenter instance for later verification of serial numbers (e.g. if all are received)
+ $fragmenterInstance = FragmenterFactory::createFragmenterInstance('package');
+
+ // Set it in this handler
+ $this->fragmenterInstance = $fragmenterInstance;
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a chunk Handler class
+ */
+ public final static function createChunkHandler () {
+ // Get new instance
+ $handlerInstance = new ChunkHandler();
+
+ // Get a FIFO stacker
+ $stackInstance = ObjectFactory::createObjectByConfiguredName('chunk_handler_stacker_class');
+
+ // Init all stacker
+ $stackInstance->initStacks(array(
+ self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP,
+ self::STACKER_NAME_CHUNKS_WITHOUT_FINAL,
+ self::STACKER_NAME_ASSEMBLED_RAW_DATA
+ ));
+
+ // Set the stacker in this handler
+ $handlerInstance->setStackInstance($stackInstance);
+
+ // Get a crypto instance ...
+ $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+
+ // ... and set it in this handler
+ $handlerInstance->setCryptoInstance($cryptoInstance);
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Initializes the handler
+ *
+ * @return void
+ */
+ private function initHandler () {
+ // Noisy debug line:
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Initializing handler ...');
+
+ // Init finalPackageChunks
+ $this->finalPackageChunks = array(
+ // Array for package content
+ 'content' => array(),
+ // ... and for the hashes
+ 'hashes' => array(),
+ // ... marker for that the final array is complete for assembling all chunks
+ 'is_complete' => FALSE,
+ // ... steps done to assemble all chunks
+ 'assemble_steps' => 0,
+ );
+
+ // ... chunkHashes:
+ $this->chunkHashes = array();
+
+ // ... eopChunk:
+ $this->eopChunk = array(
+ 0 => 'INVALID',
+ 1 => 'INVALID',
+ );
+ }
+
+ /**
+ * Checks whether the hash generated from package content is the same ("valid") as given
+ *
+ * @param $chunkSplits An array from a splitted chunk
+ * @return $isValid Whether the hash is "valid"
+ */
+ private function isChunkHashValid (array $chunkSplits) {
+ // Noisy debug line:
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: chunkSplits=' . print_r($chunkSplits, TRUE));
+
+ // Assert on some elements
+ assert(isset($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA]));
+ assert(isset($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]));
+
+ // Now hash the raw data again
+ $chunkHash = $this->getCryptoInstance()->hashString($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA], $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH], FALSE);
+
+ // Check it
+ $isValid = ($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] === $chunkHash);
+
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: chunkHash=' . $chunkHash . ',isValid=' . intval($isValid));
+
+ // ... and return it
+ return $isValid;
+ }
+
+ /**
+ * Checks whether the given serial number is valid
+ *
+ * @param $serialNumber A serial number from a chunk
+ * @return $isValid Whether the serial number is valid
+ */
+ private function isSerialNumberValid ($serialNumber) {
+ // Check it
+ $isValid = ((strlen($serialNumber) == PackageFragmenter::MAX_SERIAL_LENGTH) && ($this->hexval($serialNumber, FALSE) === $serialNumber));
+
+ // Return result
+ return $isValid;
+ }
+
+ /**
+ * Adds the chunk to the final array which will be used for the final step
+ * which will be to assemble all chunks back to the original package content
+ * and for the final hash check.
+ *
+ * This method may throw an exception if a chunk with the same serial number
+ * has already been added to avoid mixing chunks from different packages.
+ *
+ * @param $chunkSplits An array from a splitted chunk
+ * @return void
+ */
+ private function addChunkToFinalArray (array $chunkSplits) {
+ // Is the serial number (index 1) already been added?
+ if (isset($this->finalPackageChunks[$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]])) {
+ // Then throw an exception
+ throw new ChunkAlreadyAssembledException(array($this, $chunkSplits), self::EXCEPTION_CHUNK_ALREADY_ASSEMBLED);
+ } // END - if
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: serialNumber=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ',hash=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]);
+
+ // Add the chunk data (index 2) to the final array and use the serial number as index
+ $this->finalPackageChunks['content'][$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]] = $chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA];
+
+ // ... and the hash as well
+ $this->finalPackageChunks['hashes'][$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]] = $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH];
+ }
+
+ /**
+ * Marks the final array as completed, do only this if you really have all
+ * chunks together including EOP and "hash chunk".
+ *
+ * @return void
+ */
+ private function markFinalArrayAsCompleted () {
+ /*
+ * As for now, just set the array element. If any further steps are
+ * being added, this should always be the last step.
+ */
+ $this->finalPackageChunks['is_complete'] = TRUE;
+ }
+
+ /**
+ * Sorts the chunks array by using the serial number as a sorting key. In
+ * most situations a call of ksort() is enough to accomblish this. So this
+ * method may only call ksort() on the chunks array.
+ *
+ * This method sorts 'content' and 'hashes' so both must have used the
+ * serial numbers as array indexes.
+ *
+ * @return void
+ */
+ private function sortChunksArray () {
+ // Sort 'content' first
+ ksort($this->finalPackageChunks['content']);
+
+ // ... then 'hashes'
+ ksort($this->finalPackageChunks['hashes']);
+ }
+
+ /**
+ * Prepares the package assemble by removing last chunks (last shall be
+ * hash chunk, pre-last shall be EOP chunk) and verify that all serial
+ * numbers are valid (same as PackageFragmenter class would generate).
+ *
+ * @return void
+ */
+ private function preparePackageAssmble () {
+ // Make sure both arrays have same count (this however should always be TRUE)
+ assert(count($this->finalPackageChunks['hashes']) == count($this->finalPackageChunks['content']));
+ //* DIE: */ exit(__METHOD__ . ':finalPackageChunks='.print_r($this->finalPackageChunks['content'], TRUE));
+
+ /*
+ * Remove last element (hash chunk) from 'hashes'. This hash will never
+ * be needed, so ignore it.
+ */
+ array_pop($this->finalPackageChunks['hashes']);
+
+ // ... and from 'content' as well but save it for later use
+ $this->chunkHashes = explode(PackageFragmenter::CHUNK_HASH_SEPARATOR, substr(array_pop($this->finalPackageChunks['content']), strlen(PackageFragmenter::HASH_CHUNK_IDENTIFIER)));
+
+ // Remove EOP chunk and keep a copy of it
+ array_pop($this->finalPackageChunks['hashes']);
+ $this->eopChunk = explode(PackageFragmenter::CHUNK_HASH_SEPARATOR, substr(array_pop($this->finalPackageChunks['content']), strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)));
+
+ // Verify all serial numbers
+ $this->verifyChunkSerialNumbers();
+ }
+
+ /**
+ * Verifies all chunk serial numbers by using a freshly initialized
+ * fragmenter instance. Do ALWAYS sort the array and array_pop() the hash
+ * chunk before calling this method to avoid re-requests of many chunks.
+ *
+ * @return void
+ */
+ private function verifyChunkSerialNumbers () {
+ // Debug message
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: finalPackageChunks=' . print_r($this->finalPackageChunks, TRUE));
+
+ // Get final hash
+ $finalHash = $this->generateFinalHash(implode('', $this->finalPackageChunks['content']));
+
+ // Reset the serial number generator
+ $this->fragmenterInstance->resetSerialNumber($finalHash);
+
+ // "Walk" through all (content) chunks
+ foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) {
+ // Get next serial number
+ $nextSerial = $this->fragmenterInstance->getNextHexSerialNumber($finalHash);
+
+ // Debug output
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: serialNumber=' . $serialNumber . ',nextSerial=' . $nextSerial);
+
+ // Is it not the same? Then re-request it
+ if ($serialNumber != $nextSerial) {
+ // This is invalid, so remove it
+ unset($this->finalPackageChunks['content'][$serialNumber]);
+ unset($this->finalPackageChunks['hashes'][$serialNumber]);
+
+ // And re-request it with valid serial number (and hash chunk)
+ $this->rerequestChunkBySerialNumber($nextSerial);
+ } // END - if
+ } // END - foreach
+ }
+
+ /**
+ * Assembles and verifies ("final check") chunks back together to the
+ * original package (raw data for the start). This method should only be
+ * called AFTER the EOP and final-chunk chunk have been removed.
+ *
+ * @return void
+ */
+ private function assembleAllChunksToPackage () {
+ // If chunkHashes is not filled, don't continue
+ assert(count($this->chunkHashes) > 0);
+
+ // Init raw package data string
+ $this->rawPackageData = '';
+
+ // That went well, so start assembling all chunks
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Handling ' . count($this->finalPackageChunks['content']) . ' entries ...');
+ foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) {
+ // Assert on 'hash' entry (must always be set)
+ assert(isset($this->finalPackageChunks['hashes'][$serialNumber]));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: serialNumber=' . $serialNumber . ',hashes=' . $this->finalPackageChunks['hashes'][$serialNumber] . ' - validating ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('finalPackageChunks=' . print_r($this->finalPackageChunks, TRUE) . 'chunkHashes=' . print_r($this->chunkHashes, TRUE));
+
+ // Is this chunk valid? This should be the case
+ assert($this->isChunkHashValid(array(
+ self::CHUNK_SPLITS_INDEX_HASH => $this->finalPackageChunks['hashes'][$serialNumber],
+ self::CHUNK_SPLITS_INDEX_RAW_DATA => $content
+ )));
+
+ // ... and is also in the hash chunk?
+ assert(in_array($this->finalPackageChunks['hashes'][$serialNumber], $this->chunkHashes));
+
+ // Verification okay, add it to the raw data
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Adding ' . strlen($content) . ' bytes as raw package data ...');
+ $this->rawPackageData .= $content;
+ } // END - foreach
+
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: eopChunk[1]=' . $this->eopChunk[1] . ',index=' . (count($this->chunkHashes) - 2) . ',chunkHashes='.print_r($this->chunkHashes, TRUE));
+
+ // The last chunk hash must match with the one from eopChunk[1]
+ assert($this->eopChunk[1] == $this->chunkHashes[count($this->chunkHashes) - 2]);
+ }
+
+ /**
+ * Generate final hash if EOP chunk is found, else an assert will happen.
+ *
+ * @param $rawPackageData Raw package data
+ * @return $finalHash Final hash if EOP chunk is found
+ */
+ private function generateFinalHash ($rawPackageData) {
+ // Make sure the raw package data is given
+ assert((is_string($rawPackageData)) && (!empty($rawPackageData)));
+
+ // Make sure the EOP chunk is set
+ assert((isset($this->eopChunk[0])) && (isset($this->eopChunk[1])));
+ assert((is_string($this->eopChunk[0])) && (!empty($this->eopChunk[0])));
+
+ // Hash the raw data
+ $finalHash = $this->getCryptoInstance()->hashString($rawPackageData, $this->eopChunk[0], FALSE);
+
+ // Return it
+ return $finalHash;
+ }
+
+ /**
+ * Verifies the finally assembled raw package data by comparing it against
+ * the final hash.
+ *
+ * @return void
+ */
+ private function verifyRawPackageData () {
+ // Generate final hash
+ $finalHash = $this->generateFinalHash($this->rawPackageData);
+
+ // Is it the same?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: eopChunk[1]=' . $this->eopChunk[1] . ',finalHash=' . $finalHash);
+ assert($finalHash == $this->eopChunk[0]);
+ }
+
+ /**
+ * Checks whether the final (last) chunk is valid
+ *
+ * @param $chunks An array with chunks and (hopefully) a valid final chunk
+ * @return $isValid Whether the final (last) chunk is valid
+ */
+ private function isValidFinalChunk (array $chunks) {
+ // Default is all fine
+ $isValid = TRUE;
+
+ // Split the (possible) EOP chunk
+ $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunks[count($chunks) - 1]);
+
+ // Make sure chunks with only 3 elements are parsed (for details see ChunkHandler)
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('eopChunk=' . $chunks[count($chunks) - 1] . ',chunkSplits=' . print_r($chunkSplits, TRUE));
+ assert(count($chunkSplits) == 3);
+
+ // Validate final chunk
+ if (substr($chunkSplits[ChunkHandler::CHUNK_SPLITS_INDEX_RAW_DATA], 0, strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)) != PackageFragmenter::END_OF_PACKAGE_IDENTIFIER) {
+ // Not fine
+ $isValid = FALSE;
+ } elseif (substr_count($chunkSplits[ChunkHandler::CHUNK_SPLITS_INDEX_RAW_DATA], PackageFragmenter::CHUNK_HASH_SEPARATOR) != 1) {
+ // CHUNK_HASH_SEPARATOR shall only be found once
+ $isValid = FALSE;
+ }
+
+ // Return status
+ return $isValid;
+ }
+
+ /**
+ * Adds all chunks if the last one verifies as a 'final chunk'.
+ *
+ * @param $chunks An array with chunks, the last one should be a 'final'
+ * @return void
+ * @throws FinalChunkVerificationException If the final chunk does not start with 'EOP:'
+ */
+ public function addAllChunksWithFinal (array $chunks) {
+ // Try to validate the final chunk
+ try {
+ // Validate final chunk
+ $this->isValidFinalChunk($chunks);
+ } catch (AssertionException $e) {
+ // Last chunk is not valid
+ throw new FinalChunkVerificationException(array($this, $chunks, $e), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION);
+ }
+
+ // Do we have some pending chunks (no final)?
+ while (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL)) {
+ // Then get it first and add it before the EOP chunks
+ array_unshift($chunks, $this->getStackInstance()->popNamed(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL));
+ } // END - while
+
+ // Add all chunks to the FIFO stacker
+ foreach ($chunks as $chunk) {
+ // Add the chunk
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP, $chunk);
+ } // END - foreach
+ }
+
+ /**
+ * Adds all chunks and wait for more (e.g. incomplete transmission)
+ *
+ * @param $chunks An array with chunks, the last one should be a 'final'
+ * @return void
+ */
+ public function addAllChunksWait (array $chunks) {
+ // Add all chunks to the FIFO stacker
+ foreach ($chunks as $chunk) {
+ // Add the chunk
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL, $chunk);
+ } // END - foreach
+ }
+
+ /**
+ * Checks whether unhandled chunks are available
+ *
+ * @return $unhandledChunks Whether unhandled chunks are left
+ */
+ public function ifUnhandledChunksWithFinalAvailable () {
+ // Simply check if the stacker is not empty
+ $unhandledChunks = $this->getStackInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP) === FALSE;
+
+ // Return result
+ return $unhandledChunks;
+ }
+
+ /**
+ * Handles available chunks by processing one-by-one (not all together,
+ * this would slow-down the whole application) with the help of an
+ * iterator.
+ *
+ * @return void
+ */
+ public function handleAvailableChunksWithFinal () {
+ // First check if there are undhandled chunks available
+ assert($this->ifUnhandledChunksWithFinalAvailable());
+
+ // Get an entry from the stacker
+ $chunk = $this->getStackInstance()->popNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP);
+
+ // Split the string with proper separator character
+ $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunk);
+
+ /*
+ * Make sure three elements are always found:
+ * 0 = Hash
+ * 1 = Serial number
+ * 2 = Raw data
+ */
+ assert(count($chunkSplits) == 3);
+
+ // Is the generated hash from data same ("valid") as given hash?
+ if (!$this->isChunkHashValid($chunkSplits)) {
+ // Do some logging
+ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Chunk content is not validating against given hash.');
+
+ // Re-request this chunk (trust the hash in index # 0)
+ $this->rerequestChunkBySplitsArray($chunkSplits);
+
+ // Don't process this chunk
+ return;
+ } // END - if
+
+ // Is the serial number valid (chars 0-9, length equals PackageFragmenter::MAX_SERIAL_LENGTH)?
+ if (!$this->isSerialNumberValid($chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL])) {
+ // Do some logging
+ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Chunk serial number ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ' for hash ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] . ' is invalid.');
+
+ // Re-request this chunk
+ $this->rerequestChunkBySplitsArray($chunkSplits);
+
+ // Don't process this chunk
+ return;
+ } // END - if
+
+ /*
+ * It is now known that (as long as the hash algorithm has no
+ * collisions) the content is the same as the sender sends it to this
+ * peer.
+ *
+ * And also the serial number is valid (basicly) at this point. Now the
+ * chunk can be added to the final array.
+ */
+ $this->addChunkToFinalArray($chunkSplits);
+
+ // Is the stack now empty?
+ if ($this->getStackInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP)) {
+ // Then mark the final array as complete
+ $this->markFinalArrayAsCompleted();
+ } // END - if
+ }
+
+ /**
+ * Checks whether unassembled chunks are available (ready) in final array
+ *
+ * @return $unassembledChunksAvailable Whether unassembled chunks are available
+ */
+ public function ifUnassembledChunksAvailable () {
+ // For now do only check the array element 'is_complete'
+ $unassembledChunksAvailable = ($this->finalPackageChunks['is_complete'] === TRUE);
+
+ // Return status
+ return $unassembledChunksAvailable;
+ }
+
+ /**
+ * Assembles all chunks (except EOP and "hash chunk") back together to the original package data.
+ *
+ * This is done by the following steps:
+ *
+ * 1) Sort the final array with ksort(). This will bring the "hash
+ * chunk" up to the last array index and the EOP chunk to the
+ * pre-last array index
+ * 2) Assemble all chunks except two last (see above step)
+ * 3) While so, do the final check on all hashes
+ * 4) If the package is assembled back together, hash it again for
+ * the very final verification.
+ *
+ * @return void
+ */
+ public function assembleChunksFromFinalArray () {
+ // Make sure the final array is really completed
+ assert($this->ifUnassembledChunksAvailable());
+
+ // Count up stepping
+ $this->finalPackageChunks['assemble_steps']++;
+
+ // Do the next step
+ switch ($this->finalPackageChunks['assemble_steps']) {
+ case 1: // Sort the chunks array (the serial number shall act as a sorting key)
+ $this->sortChunksArray();
+ break;
+
+ case 2: // Prepare the assemble by removing last two indexes
+ $this->preparePackageAssmble();
+ break;
+
+ case 3: // Assemble all chunks back together to the original package
+ $this->assembleAllChunksToPackage();
+ break;
+
+ case 4: // Verify the raw data by hashing it again
+ $this->verifyRawPackageData();
+ break;
+
+ case 5: // Re-initialize handler to reset it to the old state
+ $this->initHandler();
+ break;
+
+ default: // Invalid step found
+ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Invalid step ' . $this->finalPackageChunks['assemble_steps'] . ' detected.');
+ break;
+ } // END - switch
+ }
+
+ /**
+ * Checks whether the raw package data has been assembled back together.
+ * This can be safely assumed when rawPackageData is not empty and the
+ * collection of all chunks is FALSE (because initHandler() will reset it).
+ *
+ * @return $isRawPackageDataAvailable Whether raw package data is available
+ */
+ public function ifRawPackageDataIsAvailable () {
+ // Check it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: this->rawPackageData()=' . strlen($this->rawPackageData) . ',ifUnassembledChunksAvailable()=' . intval($this->ifUnassembledChunksAvailable()));
+ $isRawPackageDataAvailable = ((!empty($this->rawPackageData)) && (!$this->ifUnassembledChunksAvailable()));
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: isRawPackageDataAvailable=' . intval($isRawPackageDataAvailable));
+ return $isRawPackageDataAvailable;
+ }
+
+ /**
+ * Handles the finally assembled raw package data by feeding it into another
+ * stacker for further decoding/processing.
+ *
+ * @return void
+ */
+ public function handledAssembledRawPackageData () {
+ // Assert to make sure that there is raw package data available
+ assert($this->ifRawPackageDataIsAvailable());
+
+ // Then feed it into the next stacker
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Pushing ' . strlen($this->rawPackageData) . ' bytes to stack ' . self::STACKER_NAME_ASSEMBLED_RAW_DATA . ' ...');
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_ASSEMBLED_RAW_DATA, $this->rawPackageData);
+
+ // ... and reset it
+ $this->rawPackageData = '';
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+<?php
+/**
+ * A general data Handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
+ */
+abstract class BaseDataHandler extends BaseHandler {
+ /**
+ * Last exception instance from database layer or NULL (default)
+ */
+ private $lastException = NULL;
+
+ /**
+ * Array with search criteria elements
+ */
+ protected $searchData = array();
+
+ /**
+ * Array with all data XML nodes (which hold the actual data) and their values
+ */
+ protected $messageDataElements = array();
+
+ /**
+ * Array for translating message data elements (other node's data mostly)
+ * into configuration elements.
+ */
+ protected $messageToConfig = array();
+
+ /**
+ * Array for copying configuration entries
+ */
+ protected $configCopy = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set it here
+ $this->setDhtInstance($dhtInstance);
+ }
+
+ /**
+ * Getter for search data array
+ *
+ * @return $searchData Search data array
+ */
+ public final function getSearchData () {
+ return $this->searchData;
+ }
+
+ /**
+ * Getter for last exception
+ *
+ * @return $lastException Last thrown exception
+ */
+ public final function getLastException () {
+ return $this->lastException;
+ }
+
+ /**
+ * Setter for last exception
+ *
+ * @param $lastException Last thrown exception
+ * @return void
+ */
+ public final function setLastException (FrameworkException $exceptionInstance = NULL) {
+ $this->lastException = $exceptionInstance;
+ }
+
+ /**
+ * Prepares a message as answer for given message data for delivery.
+ *
+ * @param $messageData An array with all message data
+ * @param $packageInstance An instance of a Deliverable instance
+ * @return void
+ */
+ protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send an answer message for ' . $this->getHandlerName() . ' ...');
+
+ // Get a helper instance based on this handler's name
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData));
+
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Load descriptor XML
+ $helperInstance->loadDescriptorXml($nodeInstance);
+
+ /*
+ * Set missing (temporary) configuration data, mostly it needs to be
+ * copied from message data array.
+ */
+ $this->initMessageConfigurationData($messageData);
+
+ // Compile any configuration variables
+ $helperInstance->getTemplateInstance()->compileConfigInVariables();
+
+ // Deliver the package
+ $helperInstance->sendPackage($nodeInstance);
+
+ /*
+ * Remove temporary configuration
+ */
+ $this->removeMessageConfigurationData($messageData);
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Answer message has been prepared.');
+ }
+
+ /**
+ * Prepares the next message
+ *
+ * @param $messageData An array with all message data
+ * @param $packageInstance An instance of a Deliverable instance
+ * @return void
+ */
+ protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send next message ...');
+
+ // Get a helper instance based on this handler's name
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
+
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Load descriptor XML
+ $helperInstance->loadDescriptorXml($nodeInstance);
+
+ /*
+ * Set missing (temporary) configuration data, mostly it needs to be
+ * copied from message data array.
+ */
+ $this->initMessageConfigurationData($messageData);
+
+ // Compile any configuration variables
+ $helperInstance->getTemplateInstance()->compileConfigInVariables();
+
+ // Deliver the package
+ $helperInstance->sendPackage($nodeInstance);
+
+ /*
+ * Remove temporary configuration
+ */
+ $this->removeMessageConfigurationData($messageData);
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Next message has been prepared.');
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ abstract protected function initMessageConfigurationData (array $messageData);
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ abstract protected function removeMessageConfigurationData (array $messageData);
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A NodeMessageAnnouncement handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageAnnouncementHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_announcement');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID => 'your_node_id',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash',
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash',
+ );
+
+ // Init array
+ $this->searchData = array(
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageAnnouncementHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageAnnouncementHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws AnnouncementNotAcceptedException If this node does not accept announcements
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Is this node accepting announcements?
+ if (!$nodeInstance->isAcceptingAnnouncements()) {
+ /*
+ * This node is not accepting announcements, then someone wants to
+ * announce his node to a non-bootstrap and non-master node.
+ */
+ throw new AnnouncementNotAcceptedException(array($this, $nodeInstance, $messageData), BaseHubSystem::EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED);
+ } // END - if
+
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Prepare answer message to be delivered back to the other node
+ $this->prepareAnswerMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ // Add it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Adding messageData[' . $key . ']=' . $messageData[$key] . ' ...');
+ $dataSetInstance->addCriteria($key, $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
+
+ // "Walk" throught the translation array
+ foreach ($this->messageToConfig as $messageKey => $configKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]);
+
+ // Set the element in configuration
+ $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array
+ foreach ($this->configCopy as $targetKey => $sourceKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
+
+ // Copy from source to targetKey
+ $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
+ } // END - foreach
+
+ // Translate last exception into a status code
+ $statusCode = $this->getTranslatedStatusFromLastException();
+
+ // Set it in configuration (temporarily)
+ $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // "Walk" throught the translation array again
+ foreach ($this->messageToConfig as $dummy => $configKey) {
+ // Now unset this configuration entry (to save some memory)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array again
+ foreach ($this->configCopy as $configKey => $dummy) {
+ // Now unset this configuration entry (to save some memory again)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // Remove NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS as well
+ $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A NodeMessageAnnouncementAnswer handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_announcement_answer');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
+ BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ /*
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id'
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash'
+ */
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
+ XmlAnnouncementAnswerTemplateEngine::OAANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
+ XmlAnnouncementAnswerTemplateEngine::OAANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash',
+ );
+
+ // Init array
+ $this->searchData = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageAnnouncementAnswerHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageAnnouncementAnswerHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws NoAnnouncementAttemptedException If this node has not attempted to announce itself
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Has this node attempted to announce itself?
+ if (!$nodeInstance->ifNodeIsAnnouncing()) {
+ /*
+ * This node has never announced itself, so it doesn't expect
+ * announcement answer messages.
+ */
+ throw new NoAnnouncementAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
+ } // END - if
+
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Handle the answer status element
+ $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ /*
+ * Add it, but remove any 'my-' prefixes as they are not used in
+ * database layer.
+ */
+ $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A NodeMessageDhtBootstrapAnswer handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageDhtBootstrapAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_announcement_answer');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
+ BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ /*
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id'
+ */
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
+ );
+
+ // Init array
+ $this->searchData = array(
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageDhtBootstrapAnswerHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageDhtBootstrapAnswerHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws NoDhtBootstrapAttemptedException If this DHT has not attempted to bootstrap
+ * @todo ~30% done
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Has this DHT attempted to bootstrap?
+ if (!$dhtInstance->ifDhtIsBooting()) {
+ /*
+ * This DHT has never bootstrapped, so it doesn't expect
+ * announcement answer messages.
+ */
+ throw new NoDhtBootstrapAttemptedException(array($this, $dhtInstance, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED);
+ } // END - if
+
+ // Unfinished
+ $this->partialStub('UNHANDLED: messageData=' . print_r($messageData, TRUE));
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ /*
+ * Add it, but remove any 'my-' prefixes as they are not used in
+ * database layer.
+ */
+ $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A NodeMessageRequestNodeListAnswer handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_request_node_list_answer');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
+ BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ /*
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
+ */
+ );
+
+ // Init search data array
+ $this->searchData = array(
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageRequestNodeListAnswerHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Has this node attempted to announce itself?
+ if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
+ /*
+ * This node has never announced itself, so it doesn't expect
+ * request-node-list answer messages.
+ */
+ throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
+ } // END - if
+
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Handle the answer status element
+ $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData[' . $key . ']=' . $messageData[$key]);
+
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ /*
+ * Add it, but remove any 'my-' prefixes as they are not used in
+ * database layer.
+ */
+ $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A NodeMessage??? handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 NodeMessage???Handler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_===');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ Xml???TemplateEngine::!!!_DATA_EXTERNAL_ADDRESS,
+ Xml???TemplateEngine::!!!_DATA_NODE_STATUS,
+ Xml???TemplateEngine::!!!_DATA_SESSION_ID,
+ Xml???TemplateEngine::!!!_DATA_LISTEN_PORT,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessage???Handler () {
+ // Get new instance
+ $handlerInstance = new NodeMessage???Handler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Prepare answer message to be delivered back to the other node
+ $this->prepareAnswerMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ // Add it
+ $dataSetInstance->addCriteria($key, $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general message handler, this class must be abstract to make the template
+ * method pattern working.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
+ */
+abstract class BaseMessageHandler extends BaseDataHandler {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * "Getter" for a translated last exception as a status code
+ *
+ * @return $statusCode Translated status code from last exception
+ */
+ protected function getTranslatedStatusFromLastException () {
+ // Default is all fine
+ $statusCode = BaseHubSystem::MESSAGE_STATUS_CODE_OKAY;
+
+ // Is the last exception not NULL?
+ if ($this->getLastException() instanceof FrameworkException) {
+ // "Determine" the right status code (may differ from exception to exception)
+ $this->debugInstance('lastException=' . $this->getLastException()->__toString() . ',message=' . $this->getLastException()->getMessage() . ' is not finished!');
+ } // END - if
+
+ // Return the status code
+ return $statusCode;
+ }
+
+ /**
+ * Registers an other node with this node by given message data. The
+ * following data must always be present:
+ *
+ * - session-id (for finding the node's record together with below data)
+ * - external-address (hostname or IP number)
+ * - listen-port (TCP/UDP listen port for inbound connections)
+ *
+ * @param $messageArray An array with all minimum message data
+ * @return void
+ */
+ protected function registerNodeByMessageData (array $messageData) {
+ // Check if searchData has entries
+ assert(count($this->getSearchData()) > 0);
+
+ // Let the DHT facade do the work
+ $this->getDhtInstance()->registerNodeByMessageData($messageData, $this);
+ }
+
+ /**
+ * Posty-handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function postHandleMessageData (array $messageData, Receivable $packageInstance) {
+ /*
+ * Feed hash to miner by handling over the whole array as also the
+ * sender and tags are needed.
+ */
+ $packageInstance->feedHashToMiner($messageData);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A NodeMessageDhtBootstrap handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_dht_bootstrap');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE,
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id'
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
+ );
+
+ // Init array
+ $this->searchData = array(
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageDhtBootstrapHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageDhtBootstrapHandler();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set the DHT instance here
+ $handlerInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws DhtBootstrapNotAcceptedException If this node does not accept DHT bootstrap requests
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Is this node accepting DHT bootstrap requests?
+ if (!NodeObjectFactory::createNodeInstance()->isAcceptingDhtBootstrap()) {
+ /*
+ * This node is not accepting DHT bootstrap requests.
+ */
+ throw new DhtBootstrapNotAcceptedException(array($this, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED);
+ } // END - if
+
+ // Register the DHT bootstrap requesting node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Prepare answer message to be delivered back to the other node
+ $this->prepareAnswerMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ // Add it
+ $dataSetInstance->addCriteria($key, $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-BOOTSTRAP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
+
+ // "Walk" throught the translation array
+ foreach ($this->messageToConfig as $messageKey => $configKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-BOOTSTRAP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]);
+
+ // Set the element in configuration
+ $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array
+ foreach ($this->configCopy as $targetKey => $sourceKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-BOOTSTRAP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
+
+ // Copy from source to target key
+ $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
+ } // END - foreach
+
+ // Translate last exception into a status code
+ $statusCode = $this->getTranslatedStatusFromLastException();
+
+ // Set it in configuration (temporarily)
+ $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
+
+ /*
+ * Use the DHT instance to get a list of recipients. This means that all
+ * DHT nodes that accept bootstrap requests are read from the DHT
+ * database.
+ */
+ $nodeList = $this->getDhtInstance()->findRecipientsByKey(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPT_BOOTSTRAP, 'Y');
+
+ // Make sure it is an array and has at least one entry
+ assert(is_array($nodeList));
+ assert(count($nodeList) > 0);
+
+ // Set it in configuration
+ $this->getConfigInstance()->setConfigEntry('dht_nodes', base64_encode(json_encode($nodeList)));
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // "Walk" throught the translation array again
+ foreach ($this->messageToConfig as $dummy => $configKey) {
+ // Now unset this configuration entry (to save some memory)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array again
+ foreach ($this->configCopy as $configKey => $dummy) {
+ // Now unset this configuration entry (to save some memory again)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // Remove temporary "special" values as well
+ $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
+ $this->getConfigInstance()->unsetConfigEntry('dht_nodes');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A NodeMessageRequestNodeList handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageRequestNodeListHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_request_node_list');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ );
+
+ // Init search data array
+ $this->searchData = array(
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageRequestNodeListHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageRequestNodeListHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws RequestNotAcceptedException If this node does not accept this request
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Is this node accepting announcements?
+ if (!$nodeInstance->isAcceptingNodeListRequests()) {
+ /*
+ * This node is not accepting node list requests. Throw an
+ * exception to abort any further processing.
+ */
+ throw new RequestNotAcceptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_REQUEST_NOT_ACCEPTED);
+ } // END - if
+
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Prepare answer message to be delivered back to the other node
+ $this->prepareAnswerMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ // Add it
+ $dataSetInstance->addCriteria($key, $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REQUEST-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
+
+ // "Walk" throught the config-copy array
+ foreach ($this->configCopy as $targetKey => $sourceKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REQUEST-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
+
+ // Copy from source to targetKey
+ $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
+ } // END - foreach
+
+ // Query local DHT for nodes except given session id
+ $nodeList = $this->getDhtInstance()->queryLocalNodeListExceptByMessageData(
+ $messageData,
+ $this,
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
+ BaseHubNode::OBJECT_LIST_SEPARATOR
+ );
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REQUEST-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Got a node list of ' . count($nodeList) . ' entry/-ies back.');
+
+ // Set it serialized in configuration (temporarily)
+ $this->getConfigInstance()->setConfigEntry('node_list', base64_encode(json_encode($nodeList)));
+
+ // Translate last exception into a status code
+ $statusCode = $this->getTranslatedStatusFromLastException();
+
+ // Set it in configuration (temporarily)
+ $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // "Walk" throught the config-copy array again
+ foreach ($this->configCopy as $configKey => $dummy) {
+ // Now unset this configuration entry (to save some memory again)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // Remove answer status/node list as well
+ $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
+ $this->getConfigInstance()->unsetConfigEntry('node_list');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A NodeMessageSelfConnect handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_self_connect');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageSelfConnectHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageSelfConnectHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Are node id and session id the same?
+ if (($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID] == $nodeInstance->getNodeId()) && ($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID] == $nodeInstance->getSessionId())) {
+ // Both are equal
+ self::createDebugInstance(__CLASS__)->debugOutput('SELF-CONNECT[' . __METHOD__ . ':' . __LINE__ . ']: Have connected to myself, both node and session id are equal!');
+
+ // ... and change state
+ $nodeInstance->getStateInstance()->nodeHasSelfConnected();
+ } else {
+ // Something really horrible happened
+ // @TODO Throw an exception here instead of dying
+ $this->debugInstance(__METHOD__ . ': ids mismatching! messageData=' . print_r($messageData, TRUE));
+ }
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Please don't call this method!
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Please don't call this method!
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Please don't call this method!
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+<?php
+/**
+ * A general Handler for raw data from sockets
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseRawDataHandler extends BaseHandler {
+ // Error codes:
+ // - Socket raw data stream errors
+ const SOCKET_ERROR_UNKNOWN = 'unknown_error'; // Unknown error (should not happen)
+ const SOCKET_ERROR_TRANSPORT_ENDPOINT = 'transport_endpoint'; // Transport endpoint has closed
+ const SOCKET_ERROR_INVALID_BASE64_MODULO = 'base64_modulo'; // Length is not modulo 4
+ const SOCKET_ERROR_INVALID_BASE64_MESSAGE = 'base64_message'; // Raw data is not Base64-encoded
+ const SOCKET_ERROR_UNHANDLED = 'unhandled_package'; // Unhandled raw data (not bad)
+ const SOCKET_ERROR_CONNECTION_REFUSED = 'connection_refused'; // The name says it: connection refused
+ const SOCKET_ERROR_CONNECTION_TIMED_OUT = 'connection_timed_out'; // The name says it: connection attempt has timed-out
+ const SOCKET_ERROR_OPERATION_IN_PROGRESS = 'operation_in_progress'; // 'Operation now in progress'
+ const SOCKET_ERROR_OPERATION_ALREADY_PROGRESS = 'operation_already_progress'; // 'Operation already in progress'
+ const SOCKET_ERROR_RESOURCE_UNAVAILABLE = 'resource_unavailable'; // 'Resource temporary unavailable'
+ const SOCKET_ERROR_NO_ROUTE_TO_HOST = 'no_route_to_host'; // The name says it: no route to host
+ const SOCKET_ERROR_CONNECTION_RESET_BY_PEER = 'connection_reset_by_peer'; // Connection reset by peer
+ const SOCKET_ERROR_BROKEN_PIPE = 'broken_pipe'; // Broken pipe
+ const SOCKET_CONNECTED = 'connected'; // Nothing errorous happens, socket is connected
+
+ // - Package errors
+ const PACKAGE_ERROR_INVALID_DATA = 'invalid_data'; // Invalid data in package found
+ const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
+ const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content'; // Content is invalid (e.g. not well-formed)
+ const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
+ const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package'; // Package is fine
+
+ // Package data
+ const PACKAGE_RAW_DATA = 'raw_data';
+ const PACKAGE_ERROR_CODE = 'error_code';
+
+ // Start/end marker
+ const STREAM_START_MARKER = '[[S]]';
+ const STREAM_END_MARKER = '[[E]]';
+
+ /**
+ * Stacker for raw data
+ */
+ const STACKER_NAME_RAW_DATA = 'raw_data';
+
+ /**
+ * Error code from socket
+ */
+ private $errorCode = -1;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Set error code to 'unknown'
+ $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
+
+ // Init stacker instance for processed raw data
+ $stackInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
+
+ // Remember this in this package handler
+ $this->setStackInstance($stackInstance);
+
+ // Init stacker
+ $this->initStack();
+ }
+
+ /**
+ * Initializes the stacker for raw data
+ *
+ * @return void
+ */
+ protected function initStack () {
+ $this->getStackInstance()->initStack(self::STACKER_NAME_RAW_DATA);
+ }
+
+ /**
+ * Adds given raw data to the raw data stacker
+ *
+ * @param $rawData raw data from the socket resource
+ * @return void
+ */
+ protected function addRawDataToStacker ($rawData) {
+ /*
+ * Add the deocoded data and error code to the stacker so other classes
+ * (e.g. NetworkPackage) can "pop" it from the stacker.
+ */
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_RAW_DATA, array(
+ self::PACKAGE_RAW_DATA => $rawData,
+ self::PACKAGE_ERROR_CODE => $this->getErrorCode()
+ ));
+ }
+
+ /**
+ * Checks whether raw data is pending for further processing.
+ *
+ * @return $isPending Whether raw data is pending
+ */
+ public function isRawDataPending () {
+ // Does the stacker have some entries (not empty)?
+ $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_RAW_DATA));
+
+ // Return it
+ return $isPending;
+ }
+
+ /**
+ * "Getter" for next raw data from the stacker
+ *
+ * @return $rawData Raw data from the stacker
+ */
+ public function getNextRawData () {
+ // "Pop" the raw data from the stacker
+ $rawData = $this->getStackInstance()->popNamed(self::STACKER_NAME_RAW_DATA);
+
+ // And return it
+ return $rawData;
+ }
+
+ /**
+ * Checks whether the 'recipient' field matches our own an universal node
+ * locator.
+ *
+ * @param $packageData Raw package data
+ * @return $matches Whether it matches
+ * @todo This method will be moved to a better place
+ */
+ protected function ifRecipientMatchesOwnUniversalNodeLocator (array $packageData) {
+ // Construct own address first
+ $ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator();
+
+ // Does it match?
+ $matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // Return result
+ return $matches;
+ }
+
+ /**
+ * Setter for error code
+ *
+ * @param $errorCode The error code we shall set
+ * @return void
+ */
+ public final function setErrorCode ($errorCode) {
+ $this->errorCode = $errorCode;
+ }
+
+ /**
+ * Getter for error code
+ *
+ * @return $errorCode The error code
+ */
+ public final function getErrorCode () {
+ return $this->errorCode;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+while (count($clients) > 0) {
+ // create a copy, so $clients doesn't get modified by socket_select()
+ $read = $clients;
+
+ // get a list of all the clients that have data to be read from
+ // if there are no clients with data, go to next iteration
+ $left = @socket_select($read, $write = null, $except = null, 0, 150);
+ if ($left < 1) {
+ continue;
+ }
+
+ // check if there is a client trying to connect
+ if (in_array($mainSocket, $read)) {
+ // accept the client, and add him to the $clients array
+ $new_sock = socket_accept($mainSocket);
+ $clients[] = $new_sock;
+
+ // send the client a welcome message
+ socket_write($new_sock, "No noobs, but I'll make an exception. :)\n".
+ "There are ".(count($clients) - 1)." client(s) connected to the server.\n");
+
+ socket_getpeername($new_sock, $ip);
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:New client connected: {$ip}");
+
+ // Notify all chatter
+ if (count($clients) > 2) {
+ foreach ($clients as $send_sock) {
+ if ($send_sock != $mainSocket && $send_sock != $new_sock) {
+ socket_write($send_sock, "Server: Chatter has joined from {$ip}. There are now ".(count($clients) - 1)." clients.\n");
+ }
+ }
+ }
+
+ // remove the listening socket from the clients-with-data array
+ $key = array_search($mainSocket, $read);
+ unset($read[$key]);
+ }
+
+ // loop through all the clients that have data to read from
+ foreach ($read as $read_sock) {
+ // Get client data
+ socket_getpeername($read_sock, $ip);
+
+ // read until newline or 1024 bytes
+ // socket_read while show errors when the client is disconnected, so silence the error messages
+ $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ);
+
+ // check if the client is disconnected
+ if (($data === FALSE) || (in_array(strtolower(trim($data)), $leaving))) {
+
+ // remove client for $clients array
+ $key = array_search($read_sock, $clients);
+ unset($clients[$key]);
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client from {$ip} disconnected. Left: ".(count($clients) - 1)."");
+
+ // Notify all chatter
+ if (count($clients) > 1) {
+ foreach ($clients as $send_sock) {
+ if ($send_sock != $mainSocket) {
+ socket_write($send_sock, "Server: Chatter from {$ip} has logged out. ".(count($clients) - 1)." client(s) left.\n");
+ }
+ }
+ }
+
+ // continue to the next client to read from, if any
+ socket_write($read_sock, "Server: Good bye.\n");
+ socket_shutdown($read_sock, 2);
+ socket_close($read_sock);
+ continue;
+ } elseif (in_array(trim($data), $shutdown)) {
+ // Is he allowed to shutdown?
+ if (!in_array($ip, $masters)) {
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has tried to shutdown the server!");
+ socket_write($read_sock, "Server: You are not allowed to shutdown the server!\n");
+ $data = "";
+ continue;
+ }
+
+ // Close all connections a leave here
+ foreach ($clients as $client) {
+ // Send message to client
+ if ($client !== $mainSocket && $client != $read_sock) {
+ socket_write($client, "Server: Shutting down! Thank you for joining us.\n");
+ }
+
+ // Quit him
+ socket_shutdown($client, 2);
+ socket_close($client);
+ } // end foreach
+
+ // Leave the loop
+ $data = "";
+ $clients = array();
+ continue;
+ }
+
+ // trim off the trailing/beginning white spaces
+ $data = trim($data);
+
+ // Test for HTML codes
+ $tags = strip_tags($data);
+
+ // check if there is any data after trimming off the spaces
+ if (!empty($data) && $tags == $data && count($clients) > 2) {
+ // Send confirmation to "chatter"
+ socket_write($read_sock, "\nServer: Message accepted.\n");
+
+ // send this to all the clients in the $clients array (except the first one, which is a listening socket)
+ foreach ($clients as $send_sock) {
+
+ // if its the listening sock or the client that we got the message from, go to the next one in the list
+ if ($send_sock == $mainSocket || $send_sock == $read_sock)
+ continue;
+
+ // write the message to the client -- add a newline character to the end of the message
+ socket_write($send_sock, "{$ip}:{$data}\n");
+
+ } // end of broadcast foreach
+ } elseif ($tags != $data) {
+ // HTML codes are not allowed
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has entered HTML code!");
+ socket_write($read_sock, "Server: HTML is forbidden!\n");
+ } elseif ((count($clients) == 2) && ($read_sock != $mainSocket)) {
+ // No one else will hear the "chatter"
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} speaks with himself.");
+ socket_write($read_sock, "Server: No one will hear you!\n");
+ }
+ } // end of reading foreach
+}
+
+// close the listening socket
+socket_close($mainSocket);
+
+?>
+<?php
+/**
+ * A TCP ??? listener
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Listener extends BaseListener implements Listenable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance A NodeHelper instance
+ * @return $listenerInstance An instance a prepared listener class
+ */
+ public final static function create???Listener (NodeHelper $nodeInstance) {
+ // Get new instance
+ $listenerInstance = new ???Listener();
+
+ // Set the application instance
+ $listenerInstance->setNodeInstance($nodeInstance);
+
+ // Return the prepared instance
+ return $listenerInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function initListener() {
+ $this->partialStub('Need to implement this method.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doListen() {
+ $this->partialStub('Need to implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A TCP raw data handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
+ /**
+ * Last socket error (default: Success)
+ */
+ private $lastSocketError = 0;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ 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
+ */
+ public static final function createTcpRawDataHandler () {
+ // Get new instance
+ $handlerInstance = new TcpRawDataHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Processes raw data from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the TcpListener class
+ *
+ * @param $resource A valid socket resource array
+ * @return void
+ */
+ public function processRawDataFromResource (array $socketArray) {
+ // Check the resource
+ if ((!isset($socketArray[BasePool::SOCKET_ARRAY_RESOURCE])) || (!is_resource($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]))) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Reset error code to unhandled
+ $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Handling TCP package from resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
+
+ /*
+ * Read the raw data from socket. If you change PHP_BINARY_READ to
+ * PHP_NORMAL_READ, this line will endless block. This script does only
+ * provide simultanous threads, not real.
+ */
+ $rawData = socket_read($socketArray[BasePool::SOCKET_ARRAY_RESOURCE], $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
+
+ // Get socket error code back
+ $this->lastSocketError = socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]);
+
+ // Debug output of read data length
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',MD5=' . md5($rawData) . ',resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',error=' . socket_strerror($this->lastSocketError));
+ //* NOISY-DEBUG: */ if ($rawData !== FALSE) self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: rawData=' . $rawData);
+
+ // Is it valid?
+ if ($this->lastSocketError == 11) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE]);
+
+ /*
+ * Error code 11 (Resource temporary unavailable) can be safely
+ * ignored on non-blocking sockets. The socket is currently not
+ * sending any data.
+ */
+ socket_clear_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]);
+
+ // Skip any further processing
+ return;
+ } elseif (($rawData === FALSE) || ($this->lastSocketError > 0)) {
+ // Network error or connection lost
+ $this->setErrorCode($this->lastSocketError);
+ } elseif (empty($rawData)) {
+ // The peer did send nothing to us which is now being ignored
+ return;
+ } else {
+ /*
+ * All is fine at this point. So it is okay to add the raw data to
+ * the stacker. Here it doesn't matter if the raw data is a
+ * well-formed BASE64-encoded message with start and markers. This
+ * will be checked later on.
+ */
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Adding ' . strlen($rawData) . ' bytes to stacker ...');
+ $this->addRawDataToStacker($rawData);
+ }
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A UDP raw data handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UdpRawDataHandler extends BaseRawDataHandler implements Networkable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('udp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a Networkable class
+ */
+ public static final function createUdpRawDataHandler () {
+ // Get new instance
+ $handlerInstance = new UdpRawDataHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Processes raw data from given resource. This is mostly useful for UDP
+ * package handling and is implemented in the UdpListener class
+ *
+ * @param $socketArray A valid socket resource array
+ * @return void
+ * @throws InvalidResourceException If the given resource is invalid
+ * @todo 0%
+ */
+ public function processRawDataFromResource (array $socketArray) {
+ // Check the resource
+ if ((!isset($socketArray[BasePool::SOCKET_ARRAY_RESOURCE])) || (!is_resource($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]))) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Implement processing here
+ $this->partialStub('Please implement this method. resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRRAY_CONN_TYPE]);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? protocol handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???ProtocolHandler extends BaseProtocolHandler implements HandleableProtocol, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('|||_protocol');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function create???ProtocolHandler () {
+ // Get new instance
+ $handlerInstance = new ???ProtocolHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general handler for protocols such as TCP, UDP and others.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseProtocolHandler extends BaseHandler {
+ /**
+ * Whole UNL data array
+ */
+ private $universalNodeLocatorData = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Setter for UNL data array to satify HandleableProtocol
+ *
+ * @para $unlData The UNL data array
+ * @return void
+ */
+ protected final function setUniversalNodeLocatorData (array $unlData) {
+ // Set new UNL data array
+ $this->universalNodeLocatorData = $unlData;
+ }
+
+ /**
+ * Getter for UNL data array to satify HandleableProtocol
+ *
+ * @return $unlData The UNL data array
+ */
+ public final function getUniversalNodeLocatorDataArray () {
+ // Return UNL data array
+ return $this->universalNodeLocatorData;
+ }
+
+ /**
+ * Validates given UNL very basicly by given regular expression. You
+ * normally don't need/want to overwrite this method as this is a very basic
+ * validation only based on a regex.
+ *
+ * @param $unl Universal Node Locator to validate
+ * @return $isValid Whether the UNL is valid
+ */
+ protected final function isValidUniversalNodeLocator ($unl) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ',regex=' . $regex . ' - CALLED!');
+
+ // Very basic regex check
+ $isValid = (preg_match($this->getRegularExpression(), $unl) === 1);
+
+ // Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: isValid=' . intval($isValid) . ' - EXIT!');
+ return $isValid;
+ }
+
+ /**
+ * Parses the given UNL by splitting it up in its components. The UNL ...
+ *
+ * protocol://address[:port]
+ *
+ * ... becomes:
+ *
+ * array(
+ * 'protocol' => 'value',
+ * 'address' => 'value',
+ * 'extra' => 'port'
+ * )
+ *
+ * The value for 'extra' then must be handled by parseUniversalNodeLocator()
+ * of the individual protocol handler as this is protocol-specific.
+ *
+ * @param $unl Universal Node Locator (UNL) to "parse"
+ * @return $unlData Array with all components of the UNL
+ */
+ protected function parseGenericUniversalNodeLocator ($unl) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ' - CALLED!');
+
+ // Make sure the UNL is valid
+ assert($this->isValidUniversalNodeLocator($unl));
+
+ /*
+ * "Parse" the UNL "generically", sadly this cannot be done by using preg_match() :-(
+ * @TODO If you know why, please fix and explain it to me.
+ */
+ $unlParts = explode('://', $unl);
+
+ // Split again the last part as: address:port
+ $unlParts[1] = explode(':', $unlParts[1]);
+
+ // Now there is an almost useable array which then can be copied to the "real" array.
+ $unlData = array(
+ UniversalNodeLocator::UNL_PART_PROTOCOL => $unlParts[0],
+ UniversalNodeLocator::UNL_PART_ADDRESS => $unlParts[1][0],
+ UniversalNodeLocator::UNL_PART_EXTRA => $unlParts[1][1]
+ );
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
+
+ // Return the generic array
+ return $unlData;
+ }
+
+ /**
+ * Gets an element from universalNodeLocatorData array
+ *
+ * @param $element Element in universalNodeLocatorData array
+ * @return $value Found value
+ */
+ protected final function getUniversalNodeLocatorDataElement ($element) {
+ // Is the element there?
+ assert(isset($this->universalNodeLocatorData[$element]));
+
+ // Return it
+ return $this->universalNodeLocatorData[$element];
+ }
+
+ /**
+ * "Getter" for currently saved UNL
+ *
+ * @return $unl Currently saved Universal Node Locator
+ */
+ public final function getCurrentUniversalNodeLocator () {
+ // Construct generic UNL
+ $unl = sprintf('%s://%s',
+ $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PROTOCOL),
+ $this->getAddressPart()
+ );
+
+ // Return it
+ return $unl;
+ }
+
+ /**
+ * Default implementation for returning address part, may not be suitable
+ * for IPv4/IPv6 protocol handlers. So you have to overwrite (NOT CHANGE!) this method.
+ *
+ * @return $address Address part for the final UNL
+ */
+ public function getAddressPart () {
+ // Return it
+ return $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_ADDRESS);
+ }
+
+ /**
+ * 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
+ */
+ public function isOwnAddress ($unl) {
+ // Get own external UNL
+ $externalUnl = HubTools::determineOwnExternalAddress();
+
+ // Get internal UNL
+ $internalUnl = HubTools::determineOwnInternalAddress();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ',externalUnl=' . $externalUnl . ',internalUnl=' . $internalUnl);
+ //* DIE-DEBUG: */ die(__METHOD__.':unl=' . $unl . ',this='.print_r($this, TRUE));
+
+ // Is it the same?
+ $ifMatches = (($unl === $externalUnl) || ($unl === $internalUnl));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: ifMatches=' . intval($ifMatches));
+
+ // Return result
+ return $ifMatches;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? protocol handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???ProtocolHandler extends BaseProtocolHandler implements HandleableProtocol, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('|||_protocol');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function create???ProtocolHandler () {
+ // Get new instance
+ $handlerInstance = new ???ProtocolHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general handler for IPv4 protocols such as TCP, UDP and others.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseIpV4ProtocolHandler extends BaseProtocolHandler {
+ // Regular expression for validating IP:port UNLs
+ const UNL_REGEX = '/^([a-z]{1,}):\/\/\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})$/';
+
+ /**
+ * Port number
+ */
+ private $port = 0;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Set regex
+ $this->setRegularExpression(self::UNL_REGEX);
+ }
+
+ /**
+ * Setter for port number to satify HandleableProtocol
+ *
+ * @para $port The port number
+ * @return void
+ */
+ protected final function setPort ($port) {
+ // Set new port number
+ $this->port = $port;
+ }
+
+ /**
+ * Getter for port number to satify HandleableProtocol
+ *
+ * @return $port The port number
+ */
+ public final function getPort () {
+ // Return port number
+ return $this->port;
+ }
+
+ /**
+ * Parses the given UNL by splitting it up in its components. The UNL ...
+ *
+ * protocol://address[:port]
+ *
+ * ... becomes:
+ *
+ * array(
+ * 'protocol' => 'value',
+ * 'address' => 'value',
+ * 'port' => 123
+ * )
+ *
+ * @param $unl Universal Node Locator (UNL) to "parse"
+ * @return $unlData Array with all components of the UNL
+ */
+ protected function parseUniversalNodeLocator ($unl) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ' - CALLED!');
+
+ // First generic parse
+ $unlData = parent::parseGenericUniversalNodeLocator($unl);
+
+ /*
+ * Make sure the generic parts are all there. In case of a rewrite,
+ * these assertitions will bail out on badly formed arrays.
+ */
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_EXTRA]));
+
+ // Copy 'extra' -> 'port' ...
+ $unlData[UniversalNodeLocator::UNL_PART_PORT] = $unlData[UniversalNodeLocator::UNL_PART_EXTRA];
+
+ // ... and drop 'extra'
+ unset($unlData[UniversalNodeLocator::UNL_PART_EXTRA]);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
+ return $unlData;
+ }
+
+ /**
+ * 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
+ */
+ public function isValidUniversalNodeLocatorByPackageData (array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is 'recipient' there?
+ assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+
+ // Is the correct handler choosen?
+ assert(substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($this->getHandlerName())) != $this->getHandlerName());
+
+ // Default is from generic validation
+ $isValid = $this->isValidUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: PACKAGE_DATA_RECIPIENT=' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ',isValid[' . gettype($isValid) . ']=' . intval($isValid));
+
+ // If this doesn't fail, continue validating the IP:port combination
+ if ($isValid === TRUE) {
+ // ... and validate IP:port, first "parse" the UNL
+ $unlData = $this->parseUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ /*
+ * Make sure the extra field 'port' is there. This may look
+ * superflious but in case of a rewrite this assert will stop at
+ * badly formated arrays.
+ */
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+
+ // Set whole UNL data array
+ $this->setUniversalNodeLocatorData($unlData);
+
+ // Set port
+ $this->setPort($unlData[UniversalNodeLocator::UNL_PART_PORT]);
+ } // END - if
+
+ // Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: isValid=' . intval($isValid) . ' - EXIT!');
+ return $isValid;
+ }
+
+ /**
+ * This implementation uses it's parent method and combines it with the
+ * port part to construct a valid address:port combination.
+ *
+ * @return $address Address part for the final UNL
+ */
+ public function getAddressPart () {
+ // Construct address
+ $address = sprintf('%s:%s',
+ parent::getAddressPart(),
+ $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PORT)
+ );
+
+ // Return it
+ return $address;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TCP protocol handler (IPv4)
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 TcpProtocolHandler extends BaseIpV4ProtocolHandler implements HandleableProtocol, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler and protocol type
+ $this->setHandlerName('tcp_protocol');
+ $this->setProtocolName('tcp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createTcpProtocolHandler () {
+ // Get new instance
+ $handlerInstance = new TcpProtocolHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? !!! helper class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 !!!???Helper extends BaseHubSystemHelper implements Helpable!!! {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set recipient type
+ $this->setRecipientType(NetworkPackage::NETWORK_TARGET_```);
+
+ // Set package tags
+ $this->setPackageTags(array('???'));
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public final static function create!!!???Helper () {
+ // Get new instance
+ $helperInstance = new !!!???Helper();
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the descriptor XML file
+ *
+ * @return void
+ */
+ public function loadDescriptorXml () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Do the helped attempt by delivering a package to ourselfs
+ *
+ * @param $|||Instance An instance of a !!!Helper class
+ * @return void
+ */
+ public function sendPackage (!!!Helper $|||Instance) {
+ // Sanity check: Is the ||| in the approx. state? (///)
+ $|||Instance->getStateInstance()->validate!!!StateIs+++();
+
+ // Compile the template, this inserts the loaded ||| data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ $packageInstance->enqueueRawDataFromTemplate($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general hub helper class. This class does not extend BaseHelper.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubSystemHelper extends BaseHubSystem implements HubHelper {
+ /**
+ * Recipient type
+ */
+ private $recipientType = 'invalid';
+
+ /**
+ * Package tags
+ */
+ private $packageTags = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the concrete class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Setter for recipient type
+ *
+ * @return $recipientType Type of a recipient (the helper is made for)
+ */
+ protected final function setRecipientType ($recipientType) {
+ $this->recipientType = $recipientType;
+ }
+
+ /**
+ * Getter for recipient type
+ *
+ * @return $recipientType Type of a recipient (the helper is made for)
+ */
+ public final function getRecipientType () {
+ return $this->recipientType;
+ }
+
+ /**
+ * Getter for package tags in a simple array
+ *
+ * @return $packageTags An array with all tags for the currently handled package
+ */
+ public final function getPackageTags () {
+ return $this->packageTags;
+ }
+
+ /**
+ * Setter for package tags in a simple array
+ *
+ * @param $packageTags An array with all tags for the currently handled package
+ * @return void
+ */
+ public final function setPackageTags (array $packageTags) {
+ $this->packageTags = $packageTags;
+ }
+
+ /**
+ * Tries to determine the used protocol for this package (this helper is helping to send out)
+ *
+ * @return $protocolType Type of protocol to use, usually TCP
+ * @todo 0% done
+ */
+ public function determineProtocolType () {
+ die(__METHOD__ . ':' . print_r($this, TRUE));
+ // Return it
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? connection helper class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 ???ConnectionHelper extends BaseConnectionHelper implements ConnectionHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set protocol
+ $this->setProtocolName('!!!');
+ }
+
+ /**
+ * Creates a socket resource ("connection") for given recipient in package data
+ *
+ * @param $packageData Raw package data
+ * @return $socketResource Socket resource
+ */
+ public static function createConnectionFromPackageData (array $packageData) {
+ die();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general ConnectionHelper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseConnectionHelper extends BaseHubSystemHelper implements Registerable {
+ // Exception codes
+ const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x9100;
+
+ /**
+ * Connection type 'incoming'
+ */
+ const CONNECTION_TYPE_INCOMING = 'incoming';
+
+ /**
+ * Connection type 'outgoing'
+ */
+ const CONNECTION_TYPE_OUTGOING = 'outgoing';
+
+ /**
+ * Connection type 'server'
+ */
+ const CONNECTION_TYPE_SERVER = 'server';
+
+ /**
+ * Name of used protocol for this connection
+ */
+ private $connectionType = 'invalid';
+
+ /**
+ * (IP) Adress used
+ */
+ private $address = 0;
+
+ /**
+ * Sent data in bytes
+ */
+ private $sentData = 0;
+
+ /**
+ * Whether this connection is initialized
+ */
+ private $isInitialized = FALSE;
+
+ /**
+ * Whether this connection is shutted down
+ */
+ private $shuttedDown = FALSE;
+
+ /**
+ * Currently queued chunks
+ */
+ private $queuedChunks = array();
+
+ /**
+ * Current final hash
+ */
+ private $currentFinalHash = '';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // 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);
+
+ // Get package instance from factory
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // ... and set it here
+ $this->setPackageInstance($packageInstance);
+
+ // Register this connection helper
+ Registry::getRegistry()->addInstance('connection', $this);
+
+ // Get the fragmenter instance
+ $fragmenterInstance = FragmenterFactory::createFragmenterInstance('package');
+
+ // Set it here
+ $this->setFragmenterInstance($fragmenterInstance);
+ }
+
+ /**
+ * Getter for real class name, overwrites generic method and is final
+ *
+ * @return $class Name of this class
+ */
+ public final function __toString () {
+ // Class name representation
+ $class = self::getConnectionClassName($this->getAddress(), $this->getConnectionPort(), parent::__toString());
+
+ // Return it
+ return $class;
+ }
+
+ /**
+ * Getter for connection type
+ *
+ * @return $connectionType Name of used protocol in this connection
+ */
+ public final function getConnectionType () {
+ return $this->connectionType;
+ }
+
+ /**
+ * Setter for connection type
+ *
+ * @param $connectionType Name of used protocol in this connection
+ * @return void
+ */
+ protected final function setConnectionType ($connectionType) {
+ $this->connectionType = $connectionType;
+ }
+
+ /**
+ * Getter for IP address
+ *
+ * @return $address The IP address
+ */
+ public final function getAddress () {
+ return $this->address;
+ }
+
+ /**
+ * Setter for IP address
+ *
+ * @param $address The IP address
+ * @return void
+ */
+ protected final function setAddress ($address) {
+ $this->address = $address;
+ }
+
+ /**
+ * Setter for isInitialized
+ *
+ * @param $isInitialized Name of used protocol in this connection
+ * @return void
+ */
+ protected final function setIsInitialized ($isInitialized) {
+ $this->isInitialized = $isInitialized;
+ }
+
+ /**
+ * Getter for isInitialized (NOTE: no 'get' prefix for boolean attributes!)
+ *
+ * @return $isInitialized Name of used protocol in this connection
+ */
+ protected final function isInitialized () {
+ return $this->isInitialized;
+ }
+
+ /**
+ * 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
+ */
+ public static function getConnectionClassName ($address, $port, $className) {
+ // Construct it
+ $class = $address . ':' . $port . ':' . $className;
+
+ // ... and return it
+ return $class;
+ }
+
+ /**
+ * Initializes the peer's state which sets it to 'init'
+ *
+ * @return void
+ */
+ private function initState() {
+ // Get the state factory and create the initial state.
+ PeerStateFactory::createPeerStateInstanceByName('init', $this);
+ }
+
+ /**
+ * "Getter" for raw data from a package array. A fragmenter is used which
+ * will returns us only so many raw data which fits into the back buffer.
+ * The rest is being held in a back-buffer and waits there for the next
+ * cycle and while be then sent.
+ *
+ * This method does 2 simple steps:
+ * 1) Request a chunk from set fragmenter instance
+ * 2) Finally return the chunk (array) to the caller
+ *
+ * @param $packageData Raw package data array
+ * @return $chunkData Raw data chunk
+ */
+ private function getRawDataFromPackageArray (array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: currentFinalHash=' . $this->currentFinalHash);
+
+ // Make sure the final hash is set
+ assert((is_string($this->currentFinalHash)) && (!empty($this->currentFinalHash)));
+
+ // Get the next raw data chunk from the fragmenter
+ $rawDataChunk = $this->getFragmenterInstance()->getNextRawDataChunk($this->currentFinalHash);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: rawDataChunk=' . print_r($rawDataChunk, TRUE));
+
+ // Get chunk hashes and chunk data
+ $chunkHashes = array_keys($rawDataChunk);
+ $chunkData = array_values($rawDataChunk);
+
+ // Is the required data there?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: chunkHashes[]=' . count($chunkHashes) . ',chunkData[]=' . count($chunkData));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('chunkData='.print_r($chunkData, TRUE));
+ if ((isset($chunkHashes[0])) && (isset($chunkData[0]))) {
+ // Remember this chunk as queued
+ $this->queuedChunks[$chunkHashes[0]] = $chunkData[0];
+
+ // Return the raw data
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Returning ' . strlen($chunkData[0]) . ' bytes from ' . __METHOD__ . ' ...');
+ return $chunkData[0];
+ } else {
+ // Return zero string
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Returning zero bytes from ' . __METHOD__ . '!');
+ return '';
+ }
+ }
+
+ /**
+ * "Accept" a visitor by simply calling it back
+ *
+ * @param $visitorInstance A Visitor instance
+ * @return void
+ */
+ protected final function accept (Visitor $visitorInstance) {
+ // Just call the visitor
+ $visitorInstance->visitConnectionHelper($this);
+ }
+
+ /**
+ * Sends raw package data to the recipient
+ *
+ * @param $packageData Raw package data
+ * @return void
+ * @throws InvalidSocketException If we got a problem with this socket
+ */
+ public function sendRawPackageData (array $packageData) {
+ // The helper's state must be 'connected'
+ $this->getStateInstance()->validatePeerStateConnected();
+
+ // 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);
+
+ // Set final hash
+ $this->currentFinalHash = $finalHash;
+ } // END - if
+
+ // Reset serial number
+ $this->getFragmenterInstance()->resetSerialNumber($this->currentFinalHash);
+
+ // Init variables
+ $rawData = '';
+ $dataStream = ' ';
+
+ // Fill sending buffer with data
+ while (strlen($dataStream) > 0) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE));
+
+ // Convert the package data array to a raw data stream
+ $dataStream = $this->getRawDataFromPackageArray($packageData);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Adding ' . strlen($dataStream) . ' bytes to the sending buffer ...');
+ $rawData .= $dataStream;
+ } // END - while
+
+ // Nothing to sent is bad news, so assert on it
+ assert(strlen($rawData) > 0);
+
+ // Calculate buffer size
+ $bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocolName() . '_buffer_length');
+
+ // Encode the raw data with our output-stream
+ $encodedData = $this->getOutputStreamInstance()->streamData($rawData);
+
+ // Debug message
+ //* 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
+ $diff = $encodedDataArray[NetworkPackage::RAW_BUFFER_SIZE_INDEX] - strlen($encodedDataArray[NetworkPackage::RAW_ENCODED_DATA_INDEX]);
+
+ // Push raw data to the package's outgoing stack
+ $this->getPackageInstance()->getStackInstance()->pushNamed(NetworkPackage::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
+ }
+
+ /**
+ * Getter for shuttedDown
+ *
+ * @return $shuttedDown Whether this connection is shutted down
+ */
+ public final function isShuttedDown () {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $this->__toString() . ',shuttedDown=' . intval($this->shuttedDown));
+ return $this->shuttedDown;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? connection helper class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 BaseIpV4ConnectionHelper extends BaseConnectionHelper {
+ /**
+ * Port number used
+ */
+ private $connectionPort = 0;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of implementing class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Getter for port number to satify HandleableProtocol
+ *
+ * @return $connectionPort The port number
+ */
+ public final function getConnectionPort () {
+ return $this->connectionPort;
+ }
+
+ /**
+ * Setter for port number to satify HandleableProtocol
+ *
+ * @param $connectionPort The port number
+ * @return void
+ */
+ protected final function setConnectionPort ($connectionPort) {
+ $this->connectionPort = $connectionPort;
+ }
+
+ /**
+ * Initializes the current connection
+ *
+ * @return void
+ * @throws SocketOptionException If setting any socket option fails
+ */
+ protected function initConnection () {
+ // Get socket resource
+ $socketResource = $this->getSocketResource();
+
+ // Set the option to reuse the port
+ if (!socket_set_option($socketResource, SOL_SOCKET, SO_REUSEADDR, 1)) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
+
+ // And throw again
+ // @TODO Move this to the socket error handler
+ throw new SocketOptionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ /*
+ * Set socket to non-blocking mode before trying to establish a link to
+ * it. This is now the default behaviour for all connection helpers who
+ * call initConnection(); .
+ */
+ if (!socket_set_nonblock($socketResource)) {
+ // Handle this socket error with a faked recipientData array
+ $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
+
+ // And throw again
+ throw new SocketOptionException(array($helperInstance, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ // Last step: mark connection as initialized
+ $this->setIsInitialized(TRUE);
+ }
+
+ /**
+ * Attempts to connect to a peer by given IP number and port from a valid
+ * unlData array with currently configured timeout.
+ *
+ * @param $unlData Valid UNL data array
+ * @return $isConnected Whether the connection went fine
+ * @see Please see http://de.php.net/manual/en/function.socket-connect.php#84465 for original code
+ * @todo Rewrite the while() loop to a iterator to not let the software stay very long here
+ */
+ protected function connectToPeerByUnlData (array $unlData) {
+ // Only call this if the connection is initialized by initConnection()
+ assert($this->isInitialized());
+
+ // Is unlData complete?
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+
+ // Get current time
+ $time = time();
+
+ // "Cache" socket resource and timeout config
+ $socketResource = $this->getSocketResource();
+ $timeout = $this->getConfigInstance()->getConfigEntry('socket_timeout_seconds');
+
+ // Debug output
+ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Trying to connect to ' . $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] . ':' . $unlData[UniversalNodeLocator::UNL_PART_PORT] . ' with socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' ...');
+
+ // Try to connect until it is connected
+ while ($isConnected = !@socket_connect($socketResource, $unlData[UniversalNodeLocator::UNL_PART_ADDRESS], $unlData[UniversalNodeLocator::UNL_PART_PORT])) {
+ // Get last socket error
+ $socketError = socket_last_error($socketResource);
+
+ // Skip any errors which may happen on non-blocking connections
+ if (($socketError == SOCKET_EINPROGRESS) || ($socketError == SOCKET_EALREADY)) {
+ // Now, is that attempt within parameters?
+ if ((time() - $time) >= $timeout) {
+ // Didn't work within timeout
+ $isConnected = FALSE;
+ break;
+ } // END - if
+
+ // Sleep about one second
+ $this->idle(1000);
+ } elseif ($socketError != 0) {
+ // Stop on everything else pronto
+ $isConnected = FALSE;
+ break;
+ }
+ } // END - while
+
+ // Is the peer connected?
+ if ($isConnected === TRUE) {
+ // Connection is fully established here, so change the state.
+ PeerStateFactory::createPeerStateInstanceByName('connected', $this);
+ } else {
+ /*
+ * There was a problem connecting to the peer (this state is a meta
+ * state until the error handler has found the real cause).
+ */
+ PeerStateFactory::createPeerStateInstanceByName('problem', $this);
+ }
+
+ // Return status
+ return $isConnected;
+ }
+
+ /**
+ * Marks this connection as shutted down
+ *
+ * @return void
+ */
+ protected final function markConnectionShuttedDown () {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $this->__toString() . ' has been marked as shutted down');
+ $this->shuttedDown = TRUE;
+
+ // And remove the (now invalid) socket
+ $this->setSocketResource(FALSE);
+ }
+
+ // ************************************************************************
+ // Socket error handler call-back methods
+ // ************************************************************************
+
+ /**
+ * Handles socket error 'connection timed out', but does not clear it for
+ * later debugging purposes.
+ *
+ * @param $socketResource A valid socket resource
+ * @param $unlData A valid UNL data array
+ * @return void
+ * @throws SocketConnectionException The connection attempts fails with a time-out
+ */
+ protected function socketErrorConnectionTimedOutHandler ($socketResource, array $unlData) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($socketResource);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($socketResource);
+
+ // Throw it again
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ }
+
+ /**
+ * Handles socket error 'resource temporary unavailable', but does not
+ * clear it for later debugging purposes.
+ *
+ * @param $socketResource A valid socket resource
+ * @param $unlData A valid UNL data array
+ * @return void
+ * @throws SocketConnectionException The connection attempts fails with a time-out
+ */
+ protected function socketErrorResourceUnavailableHandler ($socketResource, array $unlData) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($socketResource);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($socketResource);
+
+ // Throw it again
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ }
+
+ /**
+ * Handles socket error 'connection refused', but does not clear it for
+ * later debugging purposes.
+ *
+ * @param $socketResource A valid socket resource
+ * @param $unlData A valid UNL data array
+ * @return void
+ * @throws SocketConnectionException The connection attempts fails with a time-out
+ */
+ protected function socketErrorConnectionRefusedHandler ($socketResource, array $unlData) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($socketResource);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($socketResource);
+
+ // Throw it again
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ }
+
+ /**
+ * Handles socket error 'no route to host', but does not clear it for later
+ * debugging purposes.
+ *
+ * @param $socketResource A valid socket resource
+ * @param $unlData A valid UNL data array
+ * @return void
+ * @throws SocketConnectionException The connection attempts fails with a time-out
+ */
+ protected function socketErrorNoRouteToHostHandler ($socketResource, array $unlData) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($socketResource);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($socketResource);
+
+ // Throw it again
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ }
+
+ /**
+ * Handles socket error 'operation already in progress' which happens in
+ * method connectToPeerByUnlData() on timed out connection
+ * attempts.
+ *
+ * @param $socketResource A valid socket resource
+ * @param $unlData A valid UNL data array
+ * @return void
+ * @throws SocketConnectionException The connection attempts fails with a time-out
+ */
+ protected function socketErrorOperationAlreadyProgressHandler ($socketResource, array $unlData) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($socketResource);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Half-shutdown this socket (see there for difference to shutdownSocket())
+ $this->halfShutdownSocket($socketResource);
+
+ // Throw it again
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ }
+
+ /**
+ * Handles socket error 'connection reset by peer', but does not clear it for
+ * later debugging purposes.
+ *
+ * @param $socketResource A valid socket resource
+ * @param $unlData A valid UNL data array
+ * @return void
+ * @throws SocketConnectionException The connection attempts fails with a time-out
+ */
+ protected function socketErrorConnectionResetByPeerHandler ($socketResource, array $unlData) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($socketResource);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($socketResource);
+
+ // Throw it again
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ }
+
+ /**
+ * Handles socket "error" 'operation now in progress' which can be safely
+ * passed on with non-blocking connections.
+ *
+ * @param $socketResource A valid socket resource
+ * @param $unlData A valid UNL data array
+ * @return void
+ */
+ protected function socketErrorOperationInProgressHandler ($socketResource, array $unlData) {
+ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Operation is now in progress, this is usual for non-blocking connections and is no bug.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TCP connection helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 TcpConnectionHelper extends BaseIpV4ConnectionHelper implements ConnectionHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set protocol
+ $this->setProtocolName('tcp');
+ }
+
+ /**
+ * Creates a half-connected socket resource ("connection") for given
+ * recipient in package data. After you called this method you still need to
+ * connect to the other node.
+ *
+ * @param $packageData Raw package data
+ * @return $socketResource Socket resource
+ * @throws SocketCreationException If the socket could not be created
+ * @throws SocketOptionException If a socket option could not be set
+ * @throws SocketConnectionException If a connection could not be opened
+ * @todo $errorCode/-Message are now in handleSocketError()'s call-back methods
+ */
+ public static function createConnectionFromPackageData (array $packageData) {
+ // Create an instance
+ $helperInstance = new TcpConnectionHelper();
+
+ // Create a socket instance
+ $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+
+ // Is the socket resource valid?
+ if (!is_resource($socketResource)) {
+ /*
+ * Something bad happened, calling handleSocketError() is not
+ * possible here because that method would throw an
+ * InvalidSocketException back.
+ */
+ throw new SocketCreationException(array($helperInstance, gettype($socketResource)), BaseListener::EXCEPTION_SOCKET_CREATION_FAILED);
+ } // END - if
+
+ // Get socket error code for verification
+ $socketError = socket_last_error($socketResource);
+
+ // Check if there was an error else
+ if ($socketError > 0) {
+ // Handle this socket error with a faked recipientData array
+ $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
+
+ // Then throw again
+ 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);
+
+ // Init connection
+ $helperInstance->initConnection();
+
+ // @TODO The whole resolving part should be moved out and made more configurable
+ // Init recipient data
+ $unlData = array();
+
+ // Try to solve the recipient
+ try {
+ // Get protocol handler back from package data
+ $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
+
+ // Get UNL data
+ $unlData = $handlerInstance->getUniversalNodeLocatorDataArray();
+
+ // Make sure it is a valid Universal Node Locator array (3 elements)
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+
+ // Set handler instance
+ $helperInstance->setHandlerInstance($handlerInstance);
+ } catch (NoValidHostnameException $e) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Failed to resolve ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ':' . $e->getMessage());
+
+ // Is the recipient equal as configured IP
+ if (substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_address'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_address')) {
+ // This may connect to shipsimu.org and requests 'ip.php' which will return our external IP address
+ $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] = HubTools::determineExternalAddress();
+
+ // Do we have ip:port match?
+ // @TODO Rewrite this test for UNLs
+ if (strpos($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], ':') === FALSE) {
+ // No ip:port!
+ $helperInstance->debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' does not contain ":". Please fix this.');
+ } // END - if
+
+ // "explode" the ip:port, so index 1 will be the port number
+ // @TODO Rewrite this test for UNLs
+ $recipientArray = explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // Add the port
+ $unlData[UniversalNodeLocator::UNL_PART_PORT] = $recipientArray[UniversalNodeLocator::UNL_PART_PORT];
+ } else {
+ // It doesn't match, we need to take care of this later
+ $helperInstance->debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . '!=' . $helperInstance->getConfigInstance()->getConfigEntry('external_address'));
+ }
+ }
+
+ // Set address and maybe port
+ $helperInstance->setAddress($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]);
+ $helperInstance->setConnectionPort($unlData[UniversalNodeLocator::UNL_PART_PORT]);
+
+ // Now connect to it
+ if (!$helperInstance->connectToPeerByUnlData($unlData)) {
+ // Handle socket error
+ $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, $unlData);
+ } // END - if
+
+ // Okay, that should be it. Return it...
+ return $socketResource;
+ }
+
+ /**
+ * Do the shutdown sequence for this connection helper
+ *
+ * @return void
+ * @throws SocketShutdownException If the current socket could not be shut down
+ * @todo We may want to implement a filter for ease notification of other objects like our pool
+ */
+ public function doShutdown () {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down socket resource ' . $this->getSocketResource());
+
+ // Clear any previous errors
+ socket_clear_error($this->getSocketResource());
+
+ // Call the shutdown function on the currently set socket
+ if (!socket_shutdown($this->getSocketResource())) {
+ // Could not shutdown socket, this is fine if e.g. the other side is not connected, so analyse it
+ if (socket_last_error($this->getSocketResource()) != 107) {
+ // Something bad happened while we shutdown a socket
+ throw new SocketShutdownException($this, BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+ } // END - if
+
+ // Try to make blocking IO for socket_close()
+ socket_set_block($this->getSocketResource());
+
+ // Drop all data (don't sent any on socket closure)
+ socket_set_option($this->getSocketResource(), SOL_SOCKET, SO_LINGER, array('l_onoff' => 1, 'l_linger' => 0));
+
+ // Finally close socket to free some resources
+ socket_close($this->getSocketResource());
+
+ // Mark this connection as shutted down
+ $this->markConnectionShuttedDown();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A UDP connection helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 UdpConnectionHelper extends BaseIpV4ConnectionHelper implements ConnectionHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set protocol
+ $this->setProtocolName('udp');
+ }
+
+ /**
+ * Creates a half-connected socket resource ("connection") for given
+ * recipient in package data. After you called this method you still need to
+ * connect to the other node.
+ *
+ * @param $packageData Raw package data
+ * @return $socketResource Socket resource
+ */
+ public static function createConnectionFromPackageData (array $packageData) {
+ $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: Unfinished method, packageData[]=' . count($packageData));
+ }
+
+ /**
+ * Do the shutdown sequence for this connection helper
+ *
+ * @return void
+ * @throws SocketShutdownException If the current socket could not be shut down
+ * @todo Implement a filter for ease notification of other objects like the pool
+ */
+ public function doShutdown () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Bootstrap Dht helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 DhtBootstrapHelper extends BaseHubSystemHelper implements HelpableDht {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set recipient type
+ $this->setRecipientType(NetworkPackage::NETWORK_TARGET_DHT);
+
+ // Set package tags
+ $this->setPackageTags(array('dht_bootstrap'));
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public final static function createDhtBootstrapHelper () {
+ // Get new instance
+ $helperInstance = new DhtBootstrapHelper();
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the announcement descriptor for parsing
+ *
+ * @param $dhtInstance An instance of a Distributable class
+ * @return void
+ */
+ public function loadDescriptorXml (Distributable $dhtInstance) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Starting with DHT boostrap ...');
+
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('dht_bootstrap_template_class');
+
+ // Set it for later use
+ $this->setTemplateInstance($templateInstance);
+
+ // Read the XML descriptor
+ $templateInstance->loadXmlTemplate();
+
+ // Render the XML content
+ $templateInstance->renderXmlContent();
+ }
+
+ /**
+ * Do the helped attempt by delivering a package to ourselfs
+ *
+ * @param $dhtInstance An instance of a Distributable class
+ * @return void
+ */
+ public function sendPackage (Distributable $dhtInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ /*
+ * Sanity check: Is the DHT in the approx. state? 'init' for bootstrap
+ * nodes and 'virgin' for all others.
+ */
+ $dhtInstance->getStateInstance()->validateDhtStateIsVirginOrInit();
+
+ // Compile the template, this inserts the loaded dht data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ //* DEBUG: */ die(__METHOD__ . ':dhtInstance=' . print_r($dhtInstance, TRUE));
+ $packageInstance->enqueueRawDataFromTemplate($this);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A PublishingEntry Dht helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 DhtPublishEntryHelper extends BaseHubSystemHelper implements HelpableDht {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set recipient type
+ $this->setRecipientType(NetworkPackage::NETWORK_TARGET_DHT);
+
+ // Set package tags
+ $this->setPackageTags(array('dht_publish_entry'));
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public final static function createDhtPublishEntryHelper () {
+ // Get new instance
+ $helperInstance = new DhtPublishEntryHelper();
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the announcement descriptor for parsing
+ *
+ * @param $dhtInstance An instance of a Distributable class
+ * @return void
+ */
+ public function loadDescriptorXml (Distributable $dhtInstance) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Starting with publishing an entry ...');
+
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('dht_publish_entry_template_class');
+
+ // Set stacker
+
+ // Set it for later use
+ $this->setTemplateInstance($templateInstance);
+
+ // Read the XML descriptor
+ $templateInstance->loadXmlTemplate();
+
+ // Render the XML content
+ $templateInstance->renderXmlContent();
+ }
+
+ /**
+ * Do the helped attempt by delivering a package to ourselfs
+ *
+ * @param $dhtInstance An instance of a Distributable class
+ * @return void
+ */
+ public function sendPackage (Distributable $dhtInstance) {
+ // Compile the template, this inserts the loaded dht data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ $packageInstance->enqueueRawDataFromTemplate($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? message helper
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???MessageHelper extends BaseMessageHelper implements MessageHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $messageInstance An instance of a UnitHelper class
+ */
+ public final static function create???MessageHelper () {
+ // Get new instance
+ $messageInstance = new ???MessageHelper();
+
+ // Return the prepared instance
+ return $messageInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Message class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseMessageHelper extends BaseFrameworkSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A CryptoRandom message helper
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CryptoRandomUnitMessageHelper extends BaseMessageHelper implements MessageHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $sourceType Type of the source
+ * @return $messageInstance An instance of a UnitHelper class
+ */
+ public final static function createCryptoRandomUnitMessageHelper ($sourceType) {
+ // Get new instance
+ $messageInstance = new CryptoRandomUnitMessageHelper();
+
+ // Generate a source instance
+ $sourceInstance = UnitSourceFactory::createUnitSourceInstance($sourceType);
+
+ // Set the source instance
+ $messageInstance->setSourceInstance($sourceInstance);
+
+ // Return the prepared instance
+ return $messageInstance;
+ }
+
+ /**
+ * Generates an encrypted random message
+ *
+ * @return $encryptedMessage The encrypted random message
+ */
+ public function generateRandomMessage () {
+ // Get the message from our source
+ $encryptedMessage = $this->getSourceInstance()->generateMessageFromSource();
+
+ // Return it
+ return $encryptedMessage;
+ }
+
+ /**
+ * "Getter" for an iterator for keys
+ *
+ * @return $iteratorInstance An instance of a Iterator class
+ */
+ public function getKeyIterator () {
+ // Create the iterator instance
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('test_unit_producer_key_iterator_class');
+
+ // And return it
+ return $iteratorInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A helper class for announcing this node to other nodes
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 NodeAnnouncementHelper extends BaseNodeHelper implements HelpableNode {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set recipient type
+ $this->setRecipientType(NetworkPackage::NETWORK_TARGET_UPPER);
+
+ // Set package tags
+ $this->setPackageTags(array('announcement'));
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public static final function createNodeAnnouncementHelper () {
+ // Get new instance
+ $helperInstance = new NodeAnnouncementHelper();
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the announcement descriptor for parsing
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function loadDescriptorXml (NodeHelper $nodeInstance) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Starting with announcement to upper hubs...');
+
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_template_class');
+
+ // Set it for later use
+ $this->setTemplateInstance($templateInstance);
+
+ // Read the XML descriptor
+ $templateInstance->loadXmlTemplate();
+
+ // Render the XML content
+ $templateInstance->renderXmlContent();
+ }
+
+ /**
+ * Publishes the node's descriptor XML to all found upper nodes when the
+ * node has not yet published it's descriptor to a bootstrap node. This is
+ * done by getting the raw XML content and inserting all variables into
+ * the code. After this wents fine, the rendered content got "packaged"
+ * for network delivery.
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function sendPackage (NodeHelper $nodeInstance) {
+ // Sanity check: Is the node in the approx. state? (active)
+ $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
+
+ // Compile the template, this inserts the loaded node data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ $packageInstance->enqueueRawDataFromTemplate($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A AnnouncementMessageAnswer node helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init package tags
+ $this->setPackageTags(array('announcement_answer'));
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @param $messageData An array with all message data
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public final static function createNodeAnnouncementMessageAnswerHelper (array $messageData) {
+ // Get new instance
+ $helperInstance = new NodeAnnouncementMessageAnswerHelper();
+
+ // Set session id of other peer as recipient
+ $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
+
+ // Set message data
+ $helperInstance->setMessageData($messageData);
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the descriptor XML file
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function loadDescriptorXml (NodeHelper $nodeInstance) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting to answer an announcement...');
+
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_answer_template_class');
+
+ // Set it for later use
+ $this->setTemplateInstance($templateInstance);
+
+ // Read the XML descriptor
+ $templateInstance->loadXmlTemplate();
+
+ // Render the XML content
+ $templateInstance->renderXmlContent();
+ }
+
+ /**
+ * Send out announcement answer package
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function sendPackage (NodeHelper $nodeInstance) {
+ // Sanity check: Is the node in the approx. state? (active/reachable)
+ $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
+
+ // Compile the template, this inserts the loaded node data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ $packageInstance->enqueueRawDataFromTemplate($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general hub message answer helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubAnswerHelper extends BaseNodeHelper {
+ /**
+ * Message data array
+ */
+ private $messageData = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the concrete class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Setter for message data
+ *
+ * @return $messageData An array with message data
+ */
+ protected final function setMessageData (array $messageData) {
+ $this->messageData = $messageData;
+ }
+
+ /**
+ * Getter for message data
+ *
+ * @return $messageData An array with message data
+ */
+ public final function getMessageData () {
+ return $this->messageData;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A DhtBootstrapMessageAnswer node helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 NodeDhtBootstrapMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init package tags
+ $this->setPackageTags(array('dht_bootstrap_answer'));
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @param $messageData An array with all message data
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public final static function createNodeDhtBootstrapMessageAnswerHelper (array $messageData) {
+ // Get new instance
+ $helperInstance = new NodeDhtBootstrapMessageAnswerHelper();
+
+ // Set session id of other peer as recipient
+ $helperInstance->setRecipientType($messageData[XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID]);
+
+ // Set message data
+ $helperInstance->setMessageData($messageData);
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the descriptor XML file
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function loadDescriptorXml (NodeHelper $nodeInstance) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting to answer a DHT bootstrap request...');
+
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_dht_bootstrap_answer_template_class');
+
+ // Set it for later use
+ $this->setTemplateInstance($templateInstance);
+
+ // Read the XML descriptor
+ $templateInstance->loadXmlTemplate();
+
+ // Render the XML content
+ $templateInstance->renderXmlContent();
+ }
+
+ /**
+ * Send out announcement answer package
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function sendPackage (NodeHelper $nodeInstance) {
+ // Sanity check: Is the node in the approx. state? (active/reachable)
+ $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
+
+ // Compile the template, this inserts the loaded node data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ $packageInstance->enqueueRawDataFromTemplate($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A RequestNodeListMessageAnswer node helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 NodeRequestNodeListMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init package tags
+ $this->setPackageTags(array('request_node_list_answer'));
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @param $messageData An array with all message data
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public final static function createNodeRequestNodeListMessageAnswerHelper (array $messageData) {
+ // Get new instance
+ $helperInstance = new NodeRequestNodeListMessageAnswerHelper();
+
+ // Set session id of other peer as recipient
+ $helperInstance->setRecipientType($messageData[XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID]);
+
+ // Set message data
+ $helperInstance->setMessageData($messageData);
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the descriptor XML file
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function loadDescriptorXml (NodeHelper $nodeInstance) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting to answer a request: node-list...');
+
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_answer_template_class');
+
+ // Set it for later use
+ $this->setTemplateInstance($templateInstance);
+
+ // Read the XML descriptor
+ $templateInstance->loadXmlTemplate();
+
+ // "Cache" entries instance for next foreach loop
+ $entriesInstance = $templateInstance->getTemplateInstance();
+
+ // Is must not be NULL (then it can only be a template instance)
+ assert(!is_null($entriesInstance));
+
+ // Render the XML content
+ $templateInstance->renderXmlContent();
+ }
+
+ /**
+ * Send out request-node-list answer package
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function sendPackage (NodeHelper $nodeInstance) {
+ // Sanity check: Is the node in the approx. state? (active/reachable)
+ $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
+
+ // Compile the template, this inserts the loaded node data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ $packageInstance->enqueueRawDataFromTemplate($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? hub helper class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 Node???Helper extends BaseNodeHelper implements HelpableNode {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set recipient type
+ $this->setRecipientType(NetworkPackage::NETWORK_TARGET_!!!);
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public final static function createNode???Helper () {
+ // Get new instance
+ $helperInstance = new Node???Helper();
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the descriptor XML file
+ *
+ * @return void
+ */
+ public function loadDescriptorXml () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Do the helped attempt by delivering a package to ourselfs
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function sendPackage (NodeHelper $nodeInstance) {
+ // Sanity check: Is the node in the approx. state? (active)
+ $nodeInstance->getStateInstance()->validateNodeStateIsActive();
+
+ // Compile the template, this inserts the loaded node data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ $packageInstance->enqueueRawDataFromTemplate($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general node helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseNodeHelper extends BaseHubSystemHelper {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the concrete class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A SelfConnect hub helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set recipient type
+ $this->setRecipientType(NetworkPackage::NETWORK_TARGET_SELF);
+
+ // Set package tags
+ $this->setPackageTags(array('self_connect'));
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public static final function createNodeSelfConnectHelper () {
+ // Get new instance
+ $helperInstance = new NodeSelfConnectHelper();
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the descriptor XML file
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function loadDescriptorXml (NodeHelper $nodeInstance) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting self-connect...');
+
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_self_connect_template_class');
+
+ // Set it for later use
+ $this->setTemplateInstance($templateInstance);
+
+ // Read the XML descriptor
+ $templateInstance->loadXmlTemplate();
+
+ // Render the XML content
+ $templateInstance->renderXmlContent();
+ }
+
+ /**
+ * Do the self-connect attempt by delivering a package to ourselfs
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function sendPackage (NodeHelper $nodeInstance) {
+ // Sanity check: Is the node in the approx. state? (active)
+ $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrAnnouncing();
+
+ // Compile the template, this inserts the loaded node data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ $packageInstance->enqueueRawDataFromTemplate($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? hub helper class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 NodeRequestNodeListHelper extends BaseNodeHelper implements HelpableNode {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set recipient type
+ $this->setRecipientType(NetworkPackage::NETWORK_TARGET_UPPER);
+
+ // Set package tags
+ $this->setPackageTags(array('request_node_list'));
+ }
+
+ /**
+ * Creates the helper class
+ *
+ * @return $helperInstance A prepared instance of this helper
+ */
+ public final static function createNodeRequestNodeListHelper () {
+ // Get new instance
+ $helperInstance = new NodeRequestNodeListHelper();
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+
+ /**
+ * Loads the descriptor XML file
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function loadDescriptorXml (NodeHelper $nodeInstance) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting to request: node-list...');
+
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_template_class');
+
+ // Set it for later use
+ $this->setTemplateInstance($templateInstance);
+
+ // Read the XML descriptor
+ $templateInstance->loadXmlTemplate();
+
+ // Render the XML content
+ $templateInstance->renderXmlContent();
+ }
+
+ /**
+ * Do the helped attempt by delivering a package to ourselfs
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return void
+ */
+ public function sendPackage (NodeHelper $nodeInstance) {
+ // Sanity check: Is the node in the approx. state? (active)
+ $nodeInstance->getStateInstance()->validateNodeStateIsAnnouncementCompleted();
+
+ // Compile the template, this inserts the loaded node data into the gaps.
+ $this->getTemplateInstance()->compileTemplate();
+
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Next, feed the content in. The network package class is a pipe-through class.
+ $packageInstance->enqueueRawDataFromTemplate($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? work unit helper
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Cruncher Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???WorkUnitHelper extends BaseWorkUnitHelper implements UnitHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $unitInstance An instance of a UnitHelper class
+ */
+ public final static function create???WorkUnitHelper () {
+ // Get new instance
+ $unitInstance = new ???WorkUnitHelper();
+
+ // Return the prepared instance
+ return $unitInstance;
+ }
+
+ /**
+ * Initializes this WU helper
+ *
+ * @return void
+ * @todo 0% done
+ */
+ protected function initializeUnitHelper () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Generates a work/test/foo unit instance
+ *
+ * @return $unitInstance A work unit instance
+ * @todo 0% done
+ */
+ public function generateUnit () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general WorkUnit class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
+ */
+abstract class BaseWorkUnitHelper extends BaseFrameworkSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // All WU helpers needs to be initialized
+ $this->initializeUnitHelper();
+ }
+
+ /**
+ * Initializes this WU helper
+ *
+ * @return void
+ */
+ abstract protected function initializeUnitHelper ();
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A test unit helper for cruncher
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherTestUnitHelper extends BaseWorkUnitHelper implements UnitHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $unitInstance An instance of a UnitHelper class
+ */
+ public final static function createCruncherTestUnitHelper () {
+ // Get new instance
+ $unitInstance = new CruncherTestUnitHelper();
+
+ // Return the prepared instance
+ return $unitInstance;
+ }
+
+ /**
+ * Initializes this WU helper. This method satisfies the abstract
+ * BaseWorkUnitHelper class.
+ *
+ * @return void
+ * @todo 0% done
+ */
+ protected function initializeUnitHelper () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Generates a work/test/foo unit instance. This method satifies the
+ * UnitHelper interface.
+ *
+ * @return $unitInstance A work unit instance
+ * @todo 0% done
+ */
+ public function generateNextUnitInstance () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? information class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Info extends BaseInfo implements ShareableInfo {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $infoInstance An instance of a ShareableInfo class
+ */
+ public final static function create???Info () {
+ // Get new instance
+ $infoInstance = new ???Info();
+
+ // Return the prepared instance
+ return $infoInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Info class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 BaseInfo extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Connection information class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $infoInstance An instance of a ShareableInfo class
+ */
+ public final static function createConnectionInfo () {
+ // Get new instance
+ $infoInstance = new ConnectionInfo();
+
+ // Return the prepared instance
+ return $infoInstance;
+ }
+
+ /**
+ * Fills the information class with data from a Listenable instance
+ *
+ * @param $listenerInstance An instance of a Listenable class
+ * @return void
+ */
+ public function fillWithListenerInformation (Listenable $listenerInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $listenerInstance->getProtocolName() . ',listenerInstance=' . $listenerInstance->__toString() . ' - CALLED!');
+
+ // Fill the generic array with several data from the listener:
+ $this->setProtocolName($listenerInstance->getProtocolName());
+ $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $listenerInstance->getListenAddress());
+ $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT , $listenerInstance->getListenPort());
+
+ // Set listener here
+ $this->setListenerInstance($listenerInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Fills the information class with data from a ConnectionHelper instance
+ *
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @return void
+ */
+ public function fillWithConnectionHelperInformation (ConnectionHelper $helperInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $helperInstance->getProtocolName() . ',helperInstance=' . $helperInstance->__toString() . ',socketResource=' . $helperInstance->getSocketResource() . ' - CALLED!');
+
+ // Fill the generic array with several data from the listener:
+ $this->setProtocolName($helperInstance->getProtocolName());
+ $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $helperInstance->getAddress());
+ $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT , $helperInstance->getConnectionPort());
+
+ // Set helper here
+ $this->setHelperInstance($helperInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Getter for address
+ *
+ * @return $address Address from shared information
+ */
+ public final function getAddress () {
+ // Return it from generic array
+ return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS);
+ }
+
+ /**
+ * Getter for port
+ *
+ * @return $port Port from shared information
+ */
+ public final function getPort () {
+ // Return it from generic array
+ return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A HubPing iterator
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubPingIterator extends BaseIterator implements Iterator {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $iteratorInstance An instance of a Iterator class
+ */
+ public static final function createHubPingIterator () {
+ // Get new instance
+ $iteratorInstance = new HubPingIterator();
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ */
+ public function current () {
+ // Default is null
+ $current = NULL;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $key Current key in iteration
+ */
+ public function key () {
+ // Default is null
+ $key = NULL;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $key;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Checks whether the current entry is valid (not at the end of the list)
+ *
+ * @return void
+ */
+ public function valid () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A NetworkListen iterator
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This current implementation is not recommended, use a
+ * @todo latency-based iteration or similar approaches
+ *
+ * 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 NetworkListenIterator extends BaseIterator implements Iterator {
+ /**
+ * Key for the global list index
+ */
+ private $indexKey = 0;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listInstance A list of a Listable
+ * @return $iteratorInstance An instance a Iterator class
+ */
+ public static final function createNetworkListenIterator (Listable $listInstance) {
+ // Get new instance
+ $iteratorInstance = new NetworkListenIterator();
+
+ // Set the list
+ $iteratorInstance->setListInstance($listInstance);
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ * @throws IndexOutOfBoundsException If $indexKey is out of bounds
+ */
+ public function current () {
+ // Default is null
+ $current = NULL;
+
+ // Is the entry valid?
+ if (!$this->valid()) {
+ // Throw an exception here
+ throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
+ } // END - if
+
+ // Now get the entry
+ $current = $this->getListInstance()->getEntry($this->key());
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $indexKey Current key in iteration
+ */
+ public function key () {
+ return $this->indexKey;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->indexKey++;
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->indexKey = 0;
+ }
+
+ /**
+ * Checks whether the current entry is valid (not at the end of the list)
+ *
+ * @return $isValid Whether the current entry is there
+ */
+ public function valid () {
+ // Check for total active peers and if we are not at the end
+ $isValid = ($this->key() < $this->getListInstance()->count());
+
+ // Return result
+ return $isValid;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A handler ??? iterator
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Handler???Iterator extends BaseIterator implements Iterator {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $iteratorInstance An instance a Iterator class
+ */
+ public final static function createHandler???Iterator () {
+ // Get new instance
+ $iteratorInstance = new Handler???Iterator();
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ */
+ public function current () {
+ // Default is null
+ $current = null;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $key Current key in iteration
+ */
+ public function key () {
+ // Default is null
+ $key = null;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $key;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Checks wether the current entry is valid (not at the end of the list)
+ *
+ * @return void
+ */
+ public function valid () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A HandlerPool iterator
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This current implementation is not recommended, use a
+ * @todo latency-based iteration or similar approaches
+ *
+ * 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 HandlerPoolIterator extends BaseIterator implements Iterator {
+ /**
+ * Key for the global list index
+ */
+ private $indexKey = 0;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listInstance A list of a Listable
+ * @return $iteratorInstance An instance a Iterator class
+ */
+ public static final function createHandlerPoolIterator (Listable $listInstance) {
+ // Get new instance
+ $iteratorInstance = new HandlerPoolIterator();
+
+ // Set the list
+ $iteratorInstance->setListInstance($listInstance);
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ * @throws IndexOutOfBoundsException If $indexKey is out of bounds
+ */
+ public function current () {
+ // Default is null
+ $current = NULL;
+
+ // Is the entry valid?
+ if (!$this->valid()) {
+ // Throw an exception here
+ throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
+ } // END - if
+
+ // Now get the entry
+ $current = $this->getListInstance()->getEntry($this->key());
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $indexKey Current key in iteration
+ */
+ public function key () {
+ return $this->indexKey;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->indexKey++;
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->indexKey = 0;
+ }
+
+ /**
+ * Checks whether the current entry is valid (not at the end of the list)
+ *
+ * @return $isValid Whether the current entry is there
+ */
+ public function valid () {
+ // Check for total active peers and if we are not at the end
+ $isValid = ($this->key() < $this->getListInstance()->count());
+
+ // Return result
+ return $isValid;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A MonitorPool iterator
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This current implementation is not recommended, use a
+ * @todo latency-based iteration or similar approaches
+ *
+ * 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 MonitorPoolIterator extends BaseIterator implements Iterator, Registerable {
+ /**
+ * Key for the global list index
+ */
+ private $indexKey = 0;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listInstance A list of a Listable
+ * @return $iteratorInstance An instance a Iterator class
+ */
+ public static final function createMonitorPoolIterator (Listable $listInstance) {
+ // Get new instance
+ $iteratorInstance = new MonitorPoolIterator();
+
+ // Set the list
+ $iteratorInstance->setListInstance($listInstance);
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ * @throws IndexOutOfBoundsException If $indexKey is out of bounds
+ */
+ public function current () {
+ // Default is null
+ $current = NULL;
+
+ // Is the entry valid?
+ if (!$this->valid()) {
+ // Throw an exception here
+ throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
+ } // END - if
+
+ // Now get the entry
+ $current = $this->getListInstance()->getEntry($this->key());
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $indexKey Current key in iteration
+ */
+ public function key () {
+ return $this->indexKey;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->indexKey++;
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->indexKey = 0;
+ }
+
+ /**
+ * Checks whether the current entry is valid (not at the end of the list)
+ *
+ * @return $isValid Whether the current entry is there
+ */
+ public function valid () {
+ // Check for total active peers and if we are not at the end
+ $isValid = ($this->key() < $this->getListInstance()->count());
+
+ // Return result
+ return $isValid;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A shutdown ??? iterator
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Shutdown???Iterator extends BaseIterator implements Iterator {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $iteratorInstance An instance a Iterator class
+ */
+ public final static function createShutdown???Iterator () {
+ // Get new instance
+ $iteratorInstance = new Shutdown???Iterator();
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ */
+ public function current () {
+ // Default is null
+ $current = null;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $key Current key in iteration
+ */
+ public function key () {
+ // Default is null
+ $key = null;
+
+ $this->partialStub('Please implement this method.');
+
+ // Return it
+ return $key;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Checks wether the current entry is valid (not at the end of the list)
+ *
+ * @return void
+ */
+ public function valid () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ShutdownPool iterator
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ShutdownPoolIterator extends BaseIterator implements Iterator {
+ /**
+ * Key for the global list index
+ */
+ private $indexKey = 0;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listInstance A list of a Listable
+ * @return $iteratorInstance An instance a Iterator class
+ */
+ public static final function createShutdownPoolIterator (Listable $listInstance) {
+ // Get new instance
+ $iteratorInstance = new ShutdownPoolIterator();
+
+ // Set the list
+ $iteratorInstance->setListInstance($listInstance);
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ * @throws IndexOutOfBoundsException If $indexKey is out of bounds
+ */
+ public function current () {
+ // Default is null
+ $current = NULL;
+
+ // Is the entry valid?
+ if (!$this->valid()) {
+ // Throw an exception here
+ throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
+ } // END - if
+
+ // Now get the entry
+ $current = $this->getListInstance()->getEntry($this->key());
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $indexKey Current key in iteration
+ */
+ public function key () {
+ return $this->indexKey;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->indexKey++;
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->indexKey = 0;
+ }
+
+ /**
+ * Checks whether the current entry is valid (not at the end of the list)
+ *
+ * @return $isValid Whether the current entry is there
+ */
+ public function valid () {
+ // Check for total active peers and if we are not at the end
+ $isValid = ($this->key() < $this->getListInstance()->count());
+
+ // Return result
+ return $isValid;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TaskPool iterator
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This current implementation is not recommended, use a
+ * @todo latency-based iteration or similar approaches
+ *
+ * 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 TaskPoolIterator extends BaseIterator implements Iterator, Registerable {
+ /**
+ * Key for the global list index
+ */
+ private $indexKey = 0;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listInstance A list of a Listable
+ * @return $iteratorInstance An instance a Iterator class
+ */
+ public static final function createTaskPoolIterator (Listable $listInstance) {
+ // Get new instance
+ $iteratorInstance = new TaskPoolIterator();
+
+ // Set the list
+ $iteratorInstance->setListInstance($listInstance);
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value from group or generic
+ *
+ * @return $current Current value in iteration
+ * @throws IndexOutOfBoundsException If $indexKey is out of bounds
+ */
+ public function current () {
+ // Default is null
+ $current = NULL;
+
+ // Is the entry valid?
+ if (!$this->valid()) {
+ // Throw an exception here
+ throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
+ } // END - if
+
+ // Now get the entry
+ $current = $this->getListInstance()->getEntry($this->key());
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $indexKey Current key in iteration
+ */
+ public function key () {
+ return $this->indexKey;
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ $this->indexKey++;
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->indexKey = 0;
+ }
+
+ /**
+ * Checks whether the current entry is valid (not at the end of the list)
+ *
+ * @return $isValid Whether the current entry is there
+ */
+ public function valid () {
+ // Check for total active peers and if we are not at the end
+ $isValid = ($this->key() < $this->getListInstance()->count());
+
+ // Return result
+ return $isValid;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TestUnitKeyProducer iterator
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TestUnitKeyProducerIterator extends BaseIterator implements Iterator {
+ /**
+ * Maximum different bit combinations
+ */
+ private $maxBits = 0;
+
+ /**
+ * Key length
+ */
+ private $keyLength = 0;
+
+ /**
+ * Current iteration
+ */
+ private $currentIteration = 0;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Get key length
+ $this->keyLength = $this->getConfigInstance()->getConfigEntry('test_unit_random_secret_key_length');
+
+ // Make sure the key length isn't getting to big (32 byte = 256 bit is really, really a lot!)
+ assert($this->keyLength <= (8 * 32));
+
+ // Set max bits entry
+ $this->maxBits = pow(2, $this->keyLength);
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('ITERATOR: maxBits=' . $this->maxBits . ',keyLength=' . $this->keyLength . ' bits');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $iteratorInstance An instance of a Iterator class
+ */
+ public final static function createTestUnitKeyProducerIterator () {
+ // Get new instance
+ $iteratorInstance = new TestUnitKeyProducerIterator();
+
+ // Return the prepared instance
+ return $iteratorInstance;
+ }
+
+ /**
+ * Getter for current value
+ *
+ * @return $current Current value in iteration
+ */
+ public function current () {
+ // Calculate ASCII string representation of the key number
+ $current = $this->dec2asc($this->currentIteration);
+
+ // Prepend more zeros
+ $current = str_pad($current, ($this->keyLength / 8), chr(0), STR_PAD_LEFT);
+
+ // Return it
+ return $current;
+ }
+
+ /**
+ * Getter for key from group or generic
+ *
+ * @return $key Current key in iteration
+ * @throws UnsupportedOperationException This method should not be called
+ */
+ public function key () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Advances to the next entry
+ *
+ * @return void
+ */
+ public function next () {
+ /*
+ * This is of course a very ineffective key generation iterator because
+ * it will create a lot of keys that will never decode an encrypted
+ * message. If you know a better algorithm which is freely available and
+ * can be implemented as an itertator please contact me.
+ */
+ $this->currentIteration++;
+ }
+
+ /**
+ * Rewinds to the beginning of the iteration
+ *
+ * @return void
+ * @throws UnsupportedOperationException This method should not be called
+ */
+ public function rewind () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Checks whether the current entry is valid (not at the end of the list)
+ *
+ * @return void
+ */
+ public function valid () {
+ return ($this->currentIteration <= $this->maxBits);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A general decorator for listeners to communicate to hubs
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseListenerDecorator extends BaseDecorator implements Visitable {
+ /**
+ * Listener type
+ */
+ private $listenerType = 'invalid';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Getter for listen address
+ *
+ * @return $listenAddress The address this listener should listen on
+ */
+ public final function getListenAddress () {
+ return $this->getListenerInstance()->getListenAddress();
+ }
+
+ /**
+ * Getter for listen port
+ *
+ * @return $listenPort The port this listener should listen on
+ */
+ public final function getListenPort () {
+ return $this->getListenerInstance()->getListenPort();
+ }
+
+ /**
+ * Getter for connection type
+ *
+ * @return $connectionType Connection type for this listener
+ */
+ public final function getConnectionType () {
+ return $this->getListenerInstance()->getConnectionType();
+ }
+
+ /**
+ * Accepts the visitor to process the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this decorator
+ $visitorInstance->visitDecorator($this);
+
+ // Visit the covered class
+ $visitorInstance->visitListener($this->getListenerInstance());
+ }
+
+ /**
+ * Getter for listener type.
+ *
+ * @return $listenerType The listener's type (hub/peer)
+ */
+ public final function getListenerType () {
+ return $this->listenerType;
+ }
+
+ /**
+ * Setter for listener type.
+ *
+ * @param $listenerType The listener's type (hub/peer)
+ * @return void
+ */
+ protected final function setListenerType ($listenerType) {
+ $this->listenerType = $listenerType;
+ }
+
+ /**
+ * Getter for peer pool instance
+ *
+ * @return $poolInstance A peer pool instance
+ */
+ public final function getPoolInstance () {
+ return $this->getListenerInstance()->getPoolInstance();
+ }
+
+ /**
+ * Monitors incoming raw data from the handler and transfers it to the
+ * given receiver instance.
+ *
+ * @return void
+ */
+ public function monitorIncomingRawData () {
+ // Get the handler instance
+ $handlerInstance = $this->getListenerInstance()->getHandlerInstance();
+
+ /*
+ * Does our deocorated listener (or even a decorator again) have a
+ * handler assigned? Remember that a handler will hold all incoming raw
+ * data and not a listener.
+ */
+ if (!$handlerInstance instanceof Networkable) {
+ // Skip this silently for now. Later on, this will become mandatory!
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('No handler assigned to this listener decorator. this=' . $this->__toString() . ', listenerInstance=' . $this->getListenerInstance()->__toString());
+ return;
+ } // END - if
+
+ // Does the handler have some decoded data pending?
+ if (!$handlerInstance->isRawDataPending()) {
+ // No data is pending so skip further code silently
+ return;
+ } // END - if
+
+ // Get receiver (network package) instance
+ $receiverInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ /*
+ * We have some pending decoded data. The receiver instance is an
+ * abstract network package (which can be received and sent out) so
+ * handle the decoded data over. At this moment we don't need to know
+ * if the decoded data origins from a TCP or UDP connection so we can
+ * just pass it over to the network package receiver
+ */
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-LISTENER-DECORATOR[' . __METHOD__ . ':' . __LINE__ . '] Going to handle over some raw data to receiver instance (' . $receiverInstance->__toString() . ') ...');
+ $receiverInstance->addRawDataToIncomingStack($handlerInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+while (count($clients) > 0) {
+ // create a copy, so $clients doesn't get modified by socket_select()
+ $read = $clients;
+
+ // get a list of all the clients that have data to be read from
+ // if there are no clients with data, go to next iteration
+ $left = @socket_select($read, $write = null, $except = null, 0, 150);
+ if ($left < 1) {
+ continue;
+ }
+
+ // check if there is a client trying to connect
+ if (in_array($mainSocket, $read)) {
+ // accept the client, and add him to the $clients array
+ $new_sock = socket_accept($mainSocket);
+ $clients[] = $new_sock;
+
+ // send the client a welcome message
+ socket_write($new_sock, "No noobs, but I'll make an exception. :)\n".
+ "There are ".(count($clients) - 1)." client(s) connected to the server.\n");
+
+ socket_getpeername($new_sock, $ip);
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:New client connected: {$ip}");
+
+ // Notify all chatter
+ if (count($clients) > 2) {
+ foreach ($clients as $send_sock) {
+ if ($send_sock != $mainSocket && $send_sock != $new_sock) {
+ socket_write($send_sock, "Server: Chatter has joined from {$ip}. There are now ".(count($clients) - 1)." clients.\n");
+ }
+ }
+ }
+
+ // remove the listening socket from the clients-with-data array
+ $key = array_search($mainSocket, $read);
+ unset($read[$key]);
+ }
+
+ // loop through all the clients that have data to read from
+ foreach ($read as $read_sock) {
+ // Get client data
+ socket_getpeername($read_sock, $ip);
+
+ // read until newline or 1024 bytes
+ // socket_read while show errors when the client is disconnected, so silence the error messages
+ $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ);
+
+ // check if the client is disconnected
+ if (($data === FALSE) || (in_array(strtolower(trim($data)), $leaving))) {
+
+ // remove client for $clients array
+ $key = array_search($read_sock, $clients);
+ unset($clients[$key]);
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client from {$ip} disconnected. Left: ".(count($clients) - 1)."");
+
+ // Notify all chatter
+ if (count($clients) > 1) {
+ foreach ($clients as $send_sock) {
+ if ($send_sock != $mainSocket) {
+ socket_write($send_sock, "Server: Chatter from {$ip} has logged out. ".(count($clients) - 1)." client(s) left.\n");
+ }
+ }
+ }
+
+ // continue to the next client to read from, if any
+ socket_write($read_sock, "Server: Good bye.\n");
+ socket_shutdown($read_sock, 2);
+ socket_close($read_sock);
+ continue;
+ } elseif (in_array(trim($data), $shutdown)) {
+ // Is he allowed to shutdown?
+ if (!in_array($ip, $masters)) {
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has tried to shutdown the server!");
+ socket_write($read_sock, "Server: You are not allowed to shutdown the server!\n");
+ $data = "";
+ continue;
+ }
+
+ // Close all connections a leave here
+ foreach ($clients as $client) {
+ // Send message to client
+ if ($client !== $mainSocket && $client != $read_sock) {
+ socket_write($client, "Server: Shutting down! Thank you for joining us.\n");
+ }
+
+ // Quit him
+ socket_shutdown($client, 2);
+ socket_close($client);
+ } // end foreach
+
+ // Leave the loop
+ $data = "";
+ $clients = array();
+ continue;
+ }
+
+ // trim off the trailing/beginning white spaces
+ $data = trim($data);
+
+ // Test for HTML codes
+ $tags = strip_tags($data);
+
+ // check if there is any data after trimming off the spaces
+ if (!empty($data) && $tags == $data && count($clients) > 2) {
+ // Send confirmation to "chatter"
+ socket_write($read_sock, "\nServer: Message accepted.\n");
+
+ // send this to all the clients in the $clients array (except the first one, which is a listening socket)
+ foreach ($clients as $send_sock) {
+
+ // if its the listening sock or the client that we got the message from, go to the next one in the list
+ if ($send_sock == $mainSocket || $send_sock == $read_sock)
+ continue;
+
+ // write the message to the client -- add a newline character to the end of the message
+ socket_write($send_sock, "{$ip}:{$data}\n");
+
+ } // end of broadcast foreach
+ } elseif ($tags != $data) {
+ // HTML codes are not allowed
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has entered HTML code!");
+ socket_write($read_sock, "Server: HTML is forbidden!\n");
+ } elseif ((count($clients) == 2) && ($read_sock != $mainSocket)) {
+ // No one else will hear the "chatter"
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} speaks with himself.");
+ socket_write($read_sock, "Server: No one will hear you!\n");
+ }
+ } // end of reading foreach
+}
+
+// close the listening socket
+socket_close($mainSocket);
+
+?>
+<?php
+/**
+ * A TCP ??? listener
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Listener extends BaseListener implements Listenable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance A NodeHelper instance
+ * @return $listenerInstance An instance a prepared listener class
+ */
+ public final static function create???Listener (NodeHelper $nodeInstance) {
+ // Get new instance
+ $listenerInstance = new ???Listener();
+
+ // Set the application instance
+ $listenerInstance->setNodeInstance($nodeInstance);
+
+ // Return the prepared instance
+ return $listenerInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function initListener() {
+ $this->partialStub('Need to implement this method.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doListen() {
+ $this->partialStub('Need to implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A TCP connection listener
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TcpListener extends BaseListener implements Listenable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set the protocol to TCP
+ $this->setProtocolName('tcp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance A NodeHelper instance
+ * @return $listenerInstance An instance a prepared listener class
+ */
+ public static final function createTcpListener (NodeHelper $nodeInstance) {
+ // Get new instance
+ $listenerInstance = new TcpListener();
+
+ // Return the prepared instance
+ return $listenerInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ * @throws InvalidSocketException Thrown if the socket could not be initialized
+ */
+ public function initListener () {
+ // Create a streaming socket, of type TCP/IP
+ $mainSocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+
+ // Is the socket resource valid?
+ if (!is_resource($mainSocket)) {
+ // Something bad happened
+ throw new InvalidSocketException(array($this, $mainSocket), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ // Get socket error code for verification
+ $socketError = socket_last_error($mainSocket);
+
+ // Check if there was an error else
+ if ($socketError > 0) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
+ /*
+ // Then throw again
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, socket_strerror($socketError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+
+ // Set the option to reuse the port
+ if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
+ /*
+ // Get socket error code for verification
+ $socketError = socket_last_error($mainSocket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($mainSocket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+
+ /*
+ * "Bind" the socket to the given address, on given port so this means
+ * that all connections on this port are now our resposibility to
+ * send/recv data, disconnect, etc..
+ */
+ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
+ if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
+ /*
+ // Get socket error code for verification
+ $socketError = socket_last_error($mainSocket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($mainSocket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+
+ // Start listen for connections
+ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Listening for connections.');
+ if (!socket_listen($mainSocket)) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
+ /*
+ // Get socket error code for verification
+ $socketError = socket_last_error($mainSocket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($mainSocket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+
+ // Now, we want non-blocking mode
+ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Setting non-blocking mode.');
+ if (!socket_set_nonblock($mainSocket)) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
+ /*
+ // Get socket error code for verification
+ $socketError = socket_last_error($mainSocket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($mainSocket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+
+ // Set the main socket
+ $this->registerServerSocketResource($mainSocket);
+
+ // Initialize the peer pool instance
+ $poolInstance = ObjectFactory::createObjectByConfiguredName('node_pool_class', array($this));
+
+ // Add main socket
+ $poolInstance->addPeer($mainSocket, BaseConnectionHelper::CONNECTION_TYPE_SERVER);
+
+ // And add it to this listener
+ $this->setPoolInstance($poolInstance);
+
+ // Initialize iterator for listening on packages
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('network_listen_iterator_class', array($poolInstance->getPoolEntriesInstance()));
+
+ // Rewind it and remember it in this class
+ $iteratorInstance->rewind();
+ $this->setIteratorInstance($iteratorInstance);
+
+ // Initialize the network package handler
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('tcp_raw_data_handler_class');
+
+ // Set it in this class
+ $this->setHandlerInstance($handlerInstance);
+
+ // Output message
+ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ * @throws InvalidSocketException If an invalid socket resource has been found
+ */
+ public function doListen () {
+ // Get all readers
+ $readers = $this->getPoolInstance()->getAllSingleSockets();
+ $writers = array();
+ $excepts = array();
+
+ // Check if we have some peers left
+ $left = socket_select(
+ $readers,
+ $writers,
+ $excepts,
+ 0,
+ 150
+ );
+
+ // Some new peers found?
+ if ($left < 1) {
+ // Debug message
+ //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
+
+ // Nothing new found
+ return;
+ } // END - if
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
+
+ // Do we have changed peers?
+ if (in_array($this->getSocketResource(), $readers)) {
+ /*
+ * Then accept it, if this socket is set to non-blocking IO and the
+ * connection is NOT sending any data, socket_read() may throw
+ * error 11 (Resource temporary unavailable). This really nasty
+ * because if you have blocking IO socket_read() will wait and wait
+ * and wait ...
+ */
+ $newSocket = socket_accept($this->getSocketResource());
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketResource());
+
+ // Array for timeout settings
+ $options = array(
+ // Seconds
+ 'sec' => $this->getConfigInstance()->getConfigEntry('tcp_socket_accept_wait_sec'),
+ // Milliseconds
+ 'usec' => $this->getConfigInstance()->getConfigEntry('tcp_socket_accept_wait_usec')
+ );
+
+ // Set timeout to configured seconds
+ // @TODO Does this work on Windozer boxes???
+ if (!socket_set_option($newSocket, SOL_SOCKET, SO_RCVTIMEO, $options)) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
+ } // END - if
+
+ // Output result (only for debugging!)
+ /*
+ $option = socket_get_option($newSocket, SOL_SOCKET, SO_RCVTIMEO);
+ self::createDebugInstance(__CLASS__)->debugOutput('SO_RCVTIMEO[' . gettype($option) . ']=' . print_r($option, TRUE));
+ */
+
+ // Enable SO_OOBINLINE
+ if (!socket_set_option($newSocket, SOL_SOCKET, SO_OOBINLINE ,1)) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
+ } // END - if
+
+ // Set non-blocking
+ if (!socket_set_nonblock($newSocket)) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
+ } // END - if
+
+ // Add it to the peers
+ $this->getPoolInstance()->addPeer($newSocket, BaseConnectionHelper::CONNECTION_TYPE_INCOMING);
+
+ // Get peer name
+ if (!socket_getpeername($newSocket, $peerName)) {
+ // Handle this socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
+ } // END - if
+
+ // Get node instance
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+ // Create a faked package data array
+ $packageData = array(
+ NetworkPackage::PACKAGE_DATA_SENDER => $peerName . ':0',
+ NetworkPackage::PACKAGE_DATA_RECIPIENT => $nodeInstance->getSessionId(),
+ NetworkPackage::PACKAGE_DATA_STATUS => NetworkPackage::PACKAGE_STATUS_FAKED
+ );
+
+ // Get a connection info instance
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
+
+ // Will the info instance with listener data
+ $infoInstance->fillWithListenerInformation($this);
+
+ // Get a socket registry
+ $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+
+ // Register the socket with the registry and with the faked array
+ $registryInstance->registerSocket($infoInstance, $newSocket, $packageData);
+ } // END - if
+
+ // Do we have to rewind?
+ if (!$this->getIteratorInstance()->valid()) {
+ // Rewind the list
+ $this->getIteratorInstance()->rewind();
+ } // END - if
+
+ // Get the current value
+ $currentSocket = $this->getIteratorInstance()->current();
+
+ // Handle it here, if not main server socket
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->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())) {
+ // ... or else it will raise warnings like 'Transport endpoint is not connected'
+ $this->getHandlerInstance()->processRawDataFromResource($currentSocket);
+ } // END - if
+
+ // Advance to next entry. This should be the last line.
+ $this->getIteratorInstance()->next();
+ }
+
+ /**
+ * Checks whether the listener would accept the given package data array
+ *
+ * @param $packageData Raw package data
+ * @return $accepts Whether this listener does accept
+ * @throws UnsupportedOperationException If this method is called
+ */
+ public function ifListenerAcceptsPackageData (array $packageData) {
+ // Please don't call this
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A decorator for the TcpListener to communicate to peers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ClientTcpListenerDecorator extends BaseListenerDecorator implements Listenable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set listener type and protocol name
+ $this->setListenerType('peer');
+ $this->setProtocolName('tcp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listenerInstance A Listener instance
+ * @return $decoratorInstance An instance a prepared listener decorator class
+ */
+ public static final function createClientTcpListenerDecorator (Listenable $listenerInstance) {
+ // Get new instance
+ $decoratorInstance = new ClientTcpListenerDecorator();
+
+ // Set the application instance
+ $decoratorInstance->setListenerInstance($listenerInstance);
+
+ // Return the prepared instance
+ return $decoratorInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ */
+ public function initListener () {
+ $this->partialStub('WARNING: This method should not be called.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ */
+ public function doListen () {
+ // Handle generic TCP package
+ $this->getListenerInstance()->doListen();
+
+ // Handle peer TCP package
+ $this->partialStub('Need to handle peer TCP package.');
+ }
+
+ /**
+ * Checks whether the listener would accept the given package data array
+ *
+ * @param $packageData Raw package data
+ * @return $accepts Whether this listener does accept
+ */
+ public function ifListenerAcceptsPackageData (array $packageData) {
+ // Get a tags instance
+ $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+ // So is the package accepted with this listener?
+ $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+
+ // Return the result
+ return $accepts;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A decorator for the TcpListener to communicate to hubs
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubTcpListenerDecorator extends BaseListenerDecorator implements Listenable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set listener type and protocol name
+ $this->setListenerType('hub');
+ $this->setProtocolName('tcp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listenerInstance A Listener instance
+ * @return $decoratorInstance An instance a prepared listener decorator class
+ */
+ public static final function createHubTcpListenerDecorator (Listenable $listenerInstance) {
+ // Get new instance
+ $decoratorInstance = new HubTcpListenerDecorator();
+
+ // Set the application instance
+ $decoratorInstance->setListenerInstance($listenerInstance);
+
+ // Return the prepared instance
+ return $decoratorInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ */
+ public function initListener () {
+ $this->partialStub('WARNING: This method should not be called.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ */
+ public function doListen () {
+ // Handle generic TCP package
+ $this->getListenerInstance()->doListen();
+
+ // Handle hub TCP package
+ $this->partialStub('Need to handle hub TCP package.');
+ }
+
+ /**
+ * Checks whether the listener would accept the given package data array
+ *
+ * @param $packageData Raw package data
+ * @return $accepts Whether this listener does accept
+ */
+ public function ifListenerAcceptsPackageData (array $packageData) {
+ // Get a tags instance
+ $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+ // So is the package accepted with this listener?
+ $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+
+ // Return the result
+ return $accepts;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An UDP ??? listener
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Udp???Listener extends BaseListener implements Listenable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance A NodeHelper instance
+ * @return $listenerInstance An instance a prepared listener class
+ */
+ public final static function createUdp???Listener (NodeHelper $nodeInstance) {
+ // Get new instance
+ $listenerInstance = new Udp???Listener();
+
+ // Set the application instance
+ $listenerInstance->setNodeInstance($nodeInstance);
+
+ // Return the prepared instance
+ return $listenerInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function initListener() {
+ $this->partialStub('Need to implement this method.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doListen() {
+ $this->partialStub('Need to implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An UDP connection listener
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UdpListener extends BaseListener implements Listenable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set the protocol to UDP
+ $this->setProtocolName('udp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance A NodeHelper instance
+ * @return $listenerInstance An instance a prepared listener class
+ */
+ public static final function createUdpListener (NodeHelper $nodeInstance) {
+ // Get new instance
+ $listenerInstance = new UdpListener();
+
+ // Return the prepared instance
+ return $listenerInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ * @throws InvalidSocketException Thrown if the socket is invalid or an
+ * error was detected.
+ */
+ public function initListener () {
+ // Try to open a UDP socket
+ $mainSocket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+
+ // Is the socket a valid resource or do we have any error?
+ if (!is_resource($mainSocket)) {
+ // Then throw an InvalidSocketException
+ throw new InvalidSocketException(array($this, $mainSocket), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ /*
+ * "Bind" the socket to the given address, on given port so this means
+ * that all connections on this port are now our resposibility to
+ * send/recv data, disconnect, etc..
+ */
+ self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
+ if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
+ // Handle the socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
+ /*
+ // Get socket error code for verification
+ $socketError = socket_last_error($mainSocket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($mainSocket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+
+ // Now, we want non-blocking mode
+ self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Setting non-blocking mode.');
+ if (!socket_set_nonblock($mainSocket)) {
+ // Handle the socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
+ /*
+ // Get socket error code for verification
+ $socketError = socket_last_error($socket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($mainSocket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+
+ // Set the option to reuse the port
+ self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Setting re-use address option.');
+ if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
+ // Handle the socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
+ /*
+ // Get socket error code for verification
+ $socketError = socket_last_error($mainSocket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($mainSocket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+
+ // Remember the socket in our class
+ $this->registerServerSocketResource($mainSocket);
+
+ // Initialize the network package handler
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('udp_raw_data_handler_class');
+
+ // Set it in this class
+ $this->setHandlerInstance($handlerInstance);
+
+ // Output message
+ self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ * @todo ~50% done
+ */
+ public function doListen() {
+ // Read a package and determine the peer
+ $amount = @socket_recvfrom($this->getSocketResource(), $rawData, $this->getConfigInstance()->getConfigEntry('udp_buffer_length'), MSG_DONTWAIT, $peer, $port);
+
+ // Get last error
+ $lastError = socket_last_error($this->getSocketResource());
+
+ // Do we have an error at the line?
+ if ($lastError == 11) {
+ /*
+ * This (resource temporary unavailable) can be safely ignored on
+ * "listening" UDP ports. If we don't clear the error here, our UDP
+ * "listener" won't read any packages except if the UDP sender
+ * starts the transmission before this "listener" came up...
+ */
+ socket_clear_error($this->getSocketResource());
+
+ // Skip further processing
+ return;
+ } elseif ($lastError > 0) {
+ // Other error detected
+ self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Error detected: ' . socket_strerror($lastError));
+
+ // Skip further processing
+ return;
+ } elseif ((empty($rawData)) || (trim($peer) == '')) {
+ // Zero sized packages/peer names are usual in non-blocking mode
+ return;
+ } // END - if
+
+ // Debug only
+ self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Handling UDP package with size ' . strlen($rawData) . ' from peer ' . $peer . ':' . $port);
+ }
+
+ /**
+ * Checks whether the listener would accept the given package data array
+ *
+ * @param $packageData Raw package data
+ * @return $accepts Whether this listener does accept
+ */
+ function ifListenerAcceptsPackageData (array $packageData) {
+ $this->partialStub('This call should not happen. Please report it.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A decorator for the UdpListener to communicate to peers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ClientUdpListenerDecorator extends BaseListenerDecorator implements Listenable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set listener type and protocol name
+ $this->setListenerType('peer');
+ $this->setProtocolName('udp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listenerInstance A Listener instance
+ * @return $decoratorInstance An instance a prepared listener decorator class
+ */
+ public static final function createClientUdpListenerDecorator (Listenable $listenerInstance) {
+ // Get new instance
+ $decoratorInstance = new ClientUdpListenerDecorator();
+
+ // Set the application instance
+ $decoratorInstance->setListenerInstance($listenerInstance);
+
+ // Return the prepared instance
+ return $decoratorInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ */
+ public function initListener () {
+ $this->partialStub('WARNING: This method should not be called.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ */
+ public function doListen () {
+ // Handle generic UDP packages first
+ $this->getListenerInstance()->doListen();
+
+ // Handle this peer UDP package
+ $this->partialStub('Need to handle peer UDP package.');
+ }
+
+ /**
+ * Checks whether the listener would accept the given package data array
+ *
+ * @param $packageData Raw package data
+ * @return $accepts Whether this listener does accept
+ */
+ function ifListenerAcceptsPackageData (array $packageData) {
+ // Get a tags instance
+ $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+ // So is the package accepted with this listener?
+ $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+
+ // Return the result
+ return $accepts;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A decorator for the UdpListener to communicate to hubs
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubUdpListenerDecorator extends BaseListenerDecorator implements Listenable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set listener type and protocol name
+ $this->setListenerType('hub');
+ $this->setProtocolName('udp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listenerInstance A Listener instance
+ * @return $decoratorInstance An instance a prepared listener decorator class
+ */
+ public static final function createHubUdpListenerDecorator (Listenable $listenerInstance) {
+ // Get new instance
+ $decoratorInstance = new HubUdpListenerDecorator();
+
+ // Set the application instance
+ $decoratorInstance->setListenerInstance($listenerInstance);
+
+ // Return the prepared instance
+ return $decoratorInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ */
+ public function initListener () {
+ $this->partialStub('WARNING: This method should not be called.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ */
+ public function doListen () {
+ // Handle generic UDP package first
+ $this->getListenerInstance()->doListen();
+
+ // Handle hub UDP package
+ $this->partialStub('Need to handle hub UDP package.');
+ }
+
+ /**
+ * Checks whether the listener would accept the given package data array
+ *
+ * @param $packageData Raw package data
+ * @return $accepts Whether this listener does accept
+ */
+ public function ifListenerAcceptsPackageData (array $packageData) {
+ // Get a tags instance
+ $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+ // So is the package accepted with this listener?
+ $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+
+ // Return the result
+ return $accepts;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Hub list
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubList extends BaseList implements Listable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $listInstance An instance a Listable class
+ */
+ public static final function createHubList () {
+ // Get new instance
+ $listInstance = new HubList();
+
+ // Add groups for e.g. connected/disconnected hubs
+ $listInstance->addGroup('connected');
+ $listInstance->addGroup('disconnected');
+
+ // Return the prepared instance
+ return $listInstance;
+ }
+
+ /**
+ * "Getter" for an iterator instance of this list (not implemented)
+ *
+ * @return $iteratorInstance An instance of a Iterator class
+ */
+ public function getListIterator () {
+ $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!');
+ }
+
+ /**
+ * Clears this list by cleaning up all groups together.
+ *
+ * @return void
+ */
+ public function clearList () {
+ // Clear both groups together
+ $this->clearGroups(array('connected', 'disconnected'));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A list for pool entries
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PoolEntriesList extends BaseList implements Listable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $listInstance An instance a Listable class
+ */
+ public static final function createPoolEntriesList () {
+ // Get new instance
+ $listInstance = new PoolEntriesList();
+
+ // Add 'pool' group
+ $listInstance->addGroup('pool');
+
+ // Return the prepared instance
+ return $listInstance;
+ }
+
+ /**
+ * "Getter" for an iterator instance of this list
+ *
+ * @return $iteratorInstance An instance of a Iterator class
+ */
+ public function getListIterator () {
+ // Get the iterator instance from the factory
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName('node_ping_iterator_class', array($this));
+
+ // Rewind it
+ $iteratorInstance->rewind();
+
+ // ... and return it
+ return $iteratorInstance;
+ }
+
+ /**
+ * Clears this list by cleaning up all groups together.
+ *
+ * @return void
+ */
+ public function clearList () {
+ // Clear the only one group
+ $this->clearGroup('pool');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Recipient list
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 RecipientList extends BaseList implements Listable, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $listInstance An instance a Listable class
+ */
+ public static final function createRecipientList () {
+ // Get new instance
+ $listInstance = new RecipientList();
+
+ // Add groups:
+ // 1.) Universal Node Locators
+ $listInstance->addGroup('unl');
+
+ // 2.) Session ids
+ $listInstance->addGroup('session_id');
+
+ // Return the prepared instance
+ return $listInstance;
+ }
+
+ /**
+ * "Getter" for an iterator instance of this list (not implemented)
+ *
+ * @return $iteratorInstance An instance of a Iterator class
+ */
+ public function getListIterator () {
+ $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!');
+ }
+
+ /**
+ * Clears this list by cleaning up all groups together.
+ *
+ * @return void
+ */
+ public function clearList () {
+ // Clear both groups
+ $this->clearGroups(array('unl', 'session_id'));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? menu class for Ship-Simu
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Hub???Menu extends BaseMenu implements RenderableMenu {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $menuInstance An instance of this class
+ */
+ public final static function createHub???Menu () {
+ // Get a new instance
+ $menuInstance = new Hub???Menu();
+
+ // Return the prepared instance
+ return $menuInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A menu class for Hub
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2015 2007 - 2008 Roland Haeder, 2009 - 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 HubIndexMenu extends BaseMenu implements RenderableMenu {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $menuInstance An instance of this class
+ */
+ public static final function createHubIndexMenu () {
+ // Get a new instance
+ $menuInstance = new HubIndexMenu();
+
+ // Return the prepared instance
+ return $menuInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A hub-mcrypt miner class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 HubCoinMiner extends BaseHubMiner implements MinerHelper, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set version number
+ $this->setVersion('0.0.0');
+ }
+
+ /**
+ * Creates an instance of this hub-miner class
+ *
+ * @return $minerInstance An instance of this hub-miner class
+ */
+ public final static function createHubCoinMiner () {
+ // Get a new instance
+ $minerInstance = new HubCoinMiner();
+
+ // Return the instance
+ return $minerInstance;
+ }
+
+ /**
+ * This method fills the in-buffer with (a) test unit(s) which are mainly
+ * used for development of the crunching part. They must be enabled in
+ * configuration, or else your miner runs out of WUs and waits for more
+ * to show up.
+ *
+ * In this method we already know that the in-buffer is going depleted so
+ * no need to double-check it here.
+ *
+ * @return void
+ */
+ protected function fillInBufferQueueWithTestUnits () {
+ // Are test units enabled?
+ if ($this->getConfigInstance()->getConfigEntry('miner_test_units_enabled') == 'N') {
+ // They are disabled, so skip any further steps
+ return;
+ } elseif ($this->getStateInstance()->isMinerStateVirgin()) {
+ // No virgin miners please, because they usually have no test units ready for crunching
+ return;
+ }
+
+ // Get a test-unit generator instance
+ $generatorInstance = ObjectFactory::createObjectByConfiguredName('miner_test_unit_generator_class');
+
+ // We don't need an iterator here because we just need to generate some test units
+ for ($idx = 0; $idx < $this->getConfigInstance()->getConfigEntry('miner_max_text_unit_amount'); $idx++) {
+ // Get a test unit from it
+ $unitInstance = $generatorInstance->generateNextUnitInstance();
+
+ // ... and finally queue it to the in-buffer queue
+ $this->queueUnitInstanceToInBuffer($unitInstance);
+ } // END - for
+ }
+
+ /**
+ * This method fills the in-buffer with (real) WUs which will be crunched
+ * and the result be sent back to the key producer instance.
+ *
+ * @return void
+ */
+ protected function fillInBufferQueueWithWorkUnits () {
+ // This miner's state must not be one of these: 'virgin'
+ if ($this->getStateInstance()->isMinerStateVirgin()) {
+ // We can silently skip here, until the generation is finished
+ return;
+ } // END - if
+
+ // @TODO Implement this method
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Method to "bootstrap" the miner. This step does also apply provided
+ * command-line arguments stored in the request instance. No buffer queue
+ * will be initialized here, we only do "general" things here.
+ *
+ * @return void
+ * @todo Implement this method
+ */
+ public function doBootstrapping () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ // Output all lines
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput('Hubcoin miner v' . $this->getVersion() . ' is starting ...');
+ self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2014 Miner Developer Team');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
+ self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
+ self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ }
+
+ /**
+ * Add some miner-specific filters
+ *
+ * @param $controllerInstance An object of a Controller instance
+ * @param $responseInstance An object of a Responseable instance
+ * @return void
+ * @todo 0% done
+ */
+ public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
+ // Add some filters here
+ $this->partialStub('Please add some miner-specific filters, if required.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A hub-miner class for the '???' mode
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Hub???Miner extends BaseHubMiner implements MinerHelper, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set version number
+ $this->setVersion('x.x');
+ }
+
+ /**
+ * Creates an instance of this hub-miner class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $minerInstance An instance of this hub-miner class
+ */
+ public final static function createHub???Miner (Requestable $requestInstance) {
+ // Get a new instance
+ $minerInstance = new Hub???Miner();
+
+ // Set the request instance
+ $minerInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $minerInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the miner. This step does also apply provided
+ * command-line arguments stored in the request instance. The regular miner
+ * should communicate with the bootstrap-miners at this point.
+ *
+ * @return void
+ * @todo Implement this method
+ */
+ public function doBootstrapping () {
+ // Call generic (parent) bootstrapping method first
+ parent::doGenericBootstrapping();
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Add some miner-specific filters
+ *
+ * @return void
+ */
+ public function addExtraHubFilters () {
+ // Add some filters here
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general hub miner class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Miner 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/>.
+ */
+abstract class BaseHubMiner extends BaseHubSystem implements Updateable {
+ /**
+ * Version information
+ */
+ private $version = 'x.x';
+
+ /**
+ * By default no miner is active
+ */
+ private $isActive = FALSE;
+
+ /**
+ * All buffer queue instances (a FIFO)
+ */
+ private $bufferInstance = NULL;
+
+ /**
+ * An array for initialized producers
+ */
+ private $producersInitialized = array();
+
+ /**
+ * Stacker name for incoming queue
+ */
+ const STACKER_NAME_IN_QUEUE = 'in_queue';
+
+ /**
+ * Stacker name for outcoming queue
+ */
+ const STACKER_NAME_OUT_QUEUE = 'out_queue';
+
+ /**
+ * Maximum number of producers (2: test and real)
+ */
+ const MAX_PRODUCERS = 2;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Init this miner
+ $this->initMiner();
+ }
+
+ /**
+ * Initialize the miner generically
+ *
+ * @return void
+ */
+ private function initMiner () {
+ // Add own instance to registry
+ Registry::getRegistry()->addInstance('miner', $this);
+
+ // Init the state
+ MinerStateFactory::createMinerStateInstanceByName('init');
+ }
+
+ /**
+ * Getter for version
+ *
+ * @return $version Version number of this miner
+ */
+ protected final function getVersion () {
+ return $this->version;
+ }
+
+ /**
+ * Setter for version
+ *
+ * @param $version Version number of this miner
+ * @return void
+ */
+ protected final function setVersion ($version) {
+ $this->version = (string) $version;
+ }
+
+ /**
+ * Checks whether the in-buffer queue is filled by comparing it's current
+ * amount of entries against a threshold.
+ *
+ * @return $isFilled Whether the in-buffer is filled
+ */
+ protected function isInBufferQueueFilled () {
+ // Determine it
+ $isFilled = ($this->bufferInstance->getStackCount(self::STACKER_NAME_IN_QUEUE) > $this->getConfigInstance()->getConfigEntry('miner_in_buffer_min_threshold'));
+
+ // And return the result
+ return $isFilled;
+ }
+
+ /**
+ * This method fills the in-buffer with (a) test unit(s) which are mainly
+ * used for development of the crunching part. They must be enabled in
+ * configuration, or else your miner runs out of WUs and waits for more
+ * to show up.
+ *
+ * In this method we already know that the in-buffer is going depleted so
+ * no need to double-check it here.
+ *
+ * @return void
+ */
+ abstract protected function fillInBufferQueueWithTestUnits ();
+
+ /**
+ * This method fills the in-buffer with (real) WUs which will be crunched
+ * and the result be sent back to the key producer instance.
+ *
+ * @return void
+ */
+ abstract protected function fillInBufferQueueWithWorkUnits ();
+
+ /**
+ * Enables/disables the miner (just sets a flag)
+ *
+ * @param $version Version number of this miner
+ * @return void
+ */
+ public final function enableIsActive ($isActive = TRUE) {
+ $this->isActive = (bool) $isActive;
+ }
+
+ /**
+ * Determines whether the miner is active
+ *
+ * @return $isActive Whether the miner is active
+ */
+ public final function isActive () {
+ return $this->isActive;
+ }
+
+ /**
+ * Initializes all buffer queues (mostly in/out). This method is demanded
+ * by the MinerHelper interface.
+ *
+ * @return void
+ */
+ public function initBufferQueues () {
+ /*
+ * Initialize both buffer queues, we can use the FIFO class here
+ * directly and encapsulate its method calls with protected methods.
+ */
+ $this->bufferInstance = ObjectFactory::createObjectByConfiguredName('miner_buffer_stacker_class');
+
+ // Initialize common stackers, like in/out
+ $this->bufferInstance->initStacks(array(
+ self::STACKER_NAME_IN_QUEUE,
+ self::STACKER_NAME_OUT_QUEUE
+ ));
+
+ // Output debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('MINER: All buffers are now initialized.');
+ }
+
+ /**
+ * This method determines if the in-buffer is going to depleted and if so,
+ * it fetches more WUs from the network. If no WU can be fetched from the
+ * network and if enabled, a random test WU is being generated.
+ *
+ * This method is demanded from the MinerHelper interface.
+ *
+ * @return void
+ */
+ public function doFetchWorkUnits () {
+ // Simply check if we have enough WUs left in the in-buffer queue (a FIFO)
+ if (!$this->isInBufferQueueFilled()) {
+ // The in-buffer queue needs filling, so head out and get some work
+ $this->fillInBufferQueueWithWorkUnits();
+
+ // Is the buffer still not filled and are test-packages allowed?
+ if ((!$this->isInBufferQueueFilled()) && ($this->getConfigInstance()->getConfigEntry('miner_test_units_enabled') == 'Y')) {
+ // Then fill the in-buffer with (one) test-unit(s)
+ $this->fillInBufferQueueWithTestUnits();
+ } // END - if
+ } // END - if
+ }
+
+ /**
+ * Updates a given field with new value
+ *
+ * @param $fieldName Field to update
+ * @param $fieldValue New value to store
+ * @return void
+ * @throws DatabaseUpdateSupportException If this class does not support database updates
+ * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
+ */
+ public function updateDatabaseField ($fieldName, $fieldValue) {
+ // Unfinished
+ $this->partialStub('Unfinished!');
+ return;
+ }
+
+ /**
+ * Changes the state to 'booting' and shall be called after the block
+ * producer has been initialized.
+ *
+ * @param $producerInstance An instance of a BlockProducer class
+ * @return void
+ */
+ public function blockProducerHasInitialized (BlockProducer $producerInstance) {
+ // Make sure the state is correct ('init')
+ $this->getStateInstance()->validateMinerStateIsInit();
+
+ // Mark given producer as initialized
+ $this->producersInitialized[$producerInstance->__toString()] = TRUE;
+
+ // Has all producers been initialized?
+ if (count($this->producersInitialized) == self::MAX_PRODUCERS) {
+ // Change it to 'booting'
+ MinerStateFactory::createMinerStateInstanceByName('booting');
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A hub-node class for the 'Boot' mode
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubBootNode extends BaseHubNode implements NodeHelper, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this hub-node class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
+ */
+ public static final function createHubBootNode (Requestable $requestInstance) {
+ // Get a new instance
+ $nodeInstance = new HubBootNode();
+
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $nodeInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the node. This step does also apply provided
+ * command-line arguments stored in the request instance. The regular node
+ * should communicate with the bootstrap-nodes at this point.
+ *
+ * @return void
+ * @todo add some more special bootstrap things for this boot node
+ */
+ public function doBootstrapping () {
+ // Get UNL
+ $unl = $this->detectOwnUniversalNodeLocator();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl);
+
+ // Now check if the IP address matches one of the bootstrap nodes
+ if ($this->ifAddressMatchesBootstrapNodes($unl)) {
+ // Get our port from configuration
+ $ourPort = $this->getConfigInstance()->getConfigEntry('node_listen_port');
+
+ // Extract port
+ $bootPort = substr($this->getBootUniversalNodeLocator(), -strlen($ourPort), strlen($ourPort));
+
+ // Is the port the same?
+ if ($bootPort == $ourPort) {
+ // It is the same!
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: UNL matches bootstrap node ' . $this->getBootUniversalNodeLocator() . '.');
+
+ // Now, does the mode match
+ if ($this->getRequestInstance()->getRequestElement('mode') == self::NODE_TYPE_BOOT) {
+ // Output debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Our node is a valid bootstrap node.');
+ } else {
+ // Output warning
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Mismatching mode ' . $this->getRequestInstance()->getRequestElement('mode') . '!=' . BaseHubNode::NODE_TYPE_BOOT . ' detected.');
+ }
+ } else {
+ // IP does match, but no port
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.');
+ }
+ } else {
+ // Node does not match any know bootstrap-node
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does not match any known bootstrap-nodes.');
+ }
+
+ // Enable acceptance of announcements
+ $this->enableAcceptingAnnouncements();
+
+ // This might not be all...
+ $this->partialStub('Please implement more bootsrapping steps.');
+ }
+
+ /**
+ * Add some node-specific filters
+ *
+ * @return void
+ */
+ public function addExtraNodeFilters () {
+ // Get the application instance from registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Get the controller from the application
+ $controllerInstance = $applicationInstance->getControllerInstance();
+
+ // @TODO Add some filters here
+ $this->partialStub('Add some filters here.');
+ }
+
+ /**
+ * Adds extra tasks to the given handler for this node
+ *
+ * @param $handlerInstance An instance of a HandleableTask class
+ * @return void
+ */
+ public function addExtraTasks (HandleableTask $handlerInstance) {
+ // Prepare a task for booting the DHT
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_bootstrap_task_class');
+
+ // Register it
+ $handlerInstance->registerTask('dht_bootstrap', $taskInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+
+ /**
+ * Adds extra tasks to the given handler for this node
+ *
+ * @param $handlerInstance An instance of a HandleableTask class
+ * @return void
+ * @todo 0% done
+ */
+ public function addExtraTasks (HandleableTask $handlerInstance) {
+ $this->partialStub('Please add some tasks or empty this method.');
+ }
--- /dev/null
+<?php
+/**
+ * A hub-node class for the '???' mode
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Hub???Node extends BaseHubNode implements NodeHelper, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this hub-node class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
+ */
+ public final static function createHub???Node (Requestable $requestInstance) {
+ // Get a new instance
+ $nodeInstance = new Hub???Node();
+
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $nodeInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the node. This step does also apply provided
+ * command-line arguments stored in the request instance. The regular node
+ * should communicate with the bootstrap-nodes at this point.
+ *
+ * @return void
+ * @todo Implement this method
+ */
+ public function doBootstrapping () {
+ // Call generic (parent) bootstrapping method first
+ parent::doGenericBootstrapping();
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Initializes hub-specific queues
+ *
+ * @return void
+ * @todo Implement this method
+ */
+ public function initQueues () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Add some node-specific filters
+ *
+ * @return void
+ */
+ public function addExtraHubFilters () {
+ // Add some filters here
+ }
+
+ /**
+ * Adds extra tasks to the given handler for this node
+ *
+ * @param $handlerInstance An instance of a HandleableTask class
+ * @return void
+ * @todo 0% done
+ */
+ public function addExtraTasks (HandleableTask $handlerInstance) {
+ $this->partialStub('Please add some tasks or empty this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general hub node class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
+ /**
+ * Node types
+ */
+ const NODE_TYPE_BOOT = 'boot';
+ const NODE_TYPE_MASTER = 'master';
+ const NODE_TYPE_LIST = 'list';
+ const NODE_TYPE_REGULAR = 'regular';
+
+ // Exception constants
+ const EXCEPTION_HUB_ALREADY_ANNOUNCED = 0xe00;
+
+ // Other constants
+ const OBJECT_LIST_SEPARATOR = ',';
+
+ /**
+ * Universal node locator of bootstrap node
+ */
+ private $bootUnl = '';
+
+ /**
+ * Whether this node is anncounced (keep on FALSE!)
+ * @deprecated
+ */
+ private $hubIsAnnounced = FALSE;
+
+ /**
+ * Whether this hub is active (default: FALSE)
+ */
+ private $isActive = FALSE;
+
+ /**
+ * Whether this node accepts announcements (default: FALSE)
+ */
+ private $acceptAnnouncements = FALSE;
+
+ /**
+ * Whether this node accepts DHT bootstrap requests (default: FALSE)
+ */
+ private $acceptDhtBootstrap = FALSE;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Get a wrapper instance
+ $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_info_db_wrapper_class');
+
+ // Set it here
+ $this->setWrapperInstance($wrapperInstance);
+
+ // Get a crypto instance
+ $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+
+ // Set it here
+ $this->setCryptoInstance($cryptoInstance);
+
+ // Set the node instance in registry
+ Registry::getRegistry()->addInstance('node', $this);
+
+ // Init state which sets the state to 'init'
+ $this->initState();
+ }
+
+ /**
+ * Initializes the node's state which sets it to 'init'
+ *
+ * @return void
+ */
+ private function initState() {
+ // Get the state factory and create the initial state.
+ NodeStateFactory::createNodeStateInstanceByName('init');
+ }
+
+ /**
+ * Generates a private key and hashes it (for speeding up things)
+ *
+ * @param $searchInstance An instance of a LocalSearchCriteria class
+ * @return void
+ */
+ private function generatePrivateKeyAndHash (LocalSearchCriteria $searchInstance) {
+ // Get an RNG instance
+ $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+
+ // Generate a pseudo-random string
+ $randomString = $rngInstance->randomString(255);
+
+ // Hash and encrypt the string so we become a node id (also documented as "hub id")
+ $this->setPrivateKey($this->getCryptoInstance()->encryptString($randomString));
+ $this->setPrivateKeyHash($this->getCryptoInstance()->hashString($this->getPrivateKey()));
+
+ // Register the node id with our wrapper
+ $this->getWrapperInstance()->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance);
+
+ // Output message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . '');
+ }
+
+ /**
+ * Generates a random string from various data inluding UUID if PECL
+ * extension uuid is installed.
+ *
+ * @param $length Length of the random part
+ * @return $randomString Random string
+ * @todo Make this code more generic and move it to CryptoHelper or
+ */
+ protected function generateRamdomString ($length) {
+ // Get an RNG instance
+ $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+
+ // Generate a pseudo-random string
+ $randomString = $rngInstance->randomString($length) . ':' . $this->getBootUniversalNodeLocator() . ':' . $this->getRequestInstance()->getRequestElement('mode');
+
+ // Add UUID for even more entropy for the hasher
+ $randomString .= $this->getCryptoInstance()->createUuid();
+
+ // Return it
+ return $randomString;
+ }
+
+ /**
+ * Getter for boot UNL (Universal Node Locator)
+ *
+ * @return $bootUnl The UNL (Universal Node Locator) of the boot node
+ */
+ protected final function getBootUniversalNodeLocator () {
+ return $this->bootUnl;
+ }
+
+ /**
+ * Checks whether the given IP address matches one of the bootstrap nodes
+ *
+ * @param $remoteAddr IP address to checkout against our bootstrapping list
+ * @return $isFound Whether the IP is found
+ */
+ protected function ifAddressMatchesBootstrapNodes ($remoteAddr) {
+ // By default nothing is found
+ $isFound = FALSE;
+
+ // Run through all configured IPs
+ foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) {
+ // Does it match?
+ if ($unl == $remoteAddr) {
+ // Found it!
+ $isFound = TRUE;
+
+ // Remember the UNL
+ $this->bootUnl = $unl;
+
+ // Output message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: UNL matches remote address ' . $unl . '.');
+
+ // Stop further searching
+ break;
+ } elseif ($unl == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
+ /*
+ * IP matches listen address. At this point we really don't care
+ * if we can really listen on that address
+ */
+ $isFound = TRUE;
+
+ // Remember the port number
+ $this->bootUnl = $unl;
+
+ // Output message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: UNL matches listen address ' . $unl . '.');
+
+ // Stop further searching
+ break;
+ }
+ } // END - foreach
+
+ // Return the result
+ return $isFound;
+ }
+
+ /**
+ * Tries to detect own UNL (Universal Node Locator)
+ *
+ * @return $unl Node's own universal node locator
+ */
+ public function detectOwnUniversalNodeLocator () {
+ // Is "cache" set?
+ if (!isset($GLOBALS[__METHOD__])) {
+ // Get the UNL array back
+ $unlData = $this->getUniversalNodeLocatorArray();
+
+ // There are 2 UNLs, internal and external.
+ if ($this->getConfigInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
+ // Public "external" UNL address
+ $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL];
+ } else {
+ // Non-public "internal" UNL address
+ $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL];
+ }
+ } // END - if
+
+ // Return it
+ return $GLOBALS[__METHOD__];
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ public function outputConsoleTeaser () {
+ // Get the app instance (for shortening our code)
+ $app = $this->getApplicationInstance();
+
+ // Output all lines
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
+ self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2015 Hub Developer Team');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
+ self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
+ self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
+ self::createDebugInstance(__CLASS__)->debugOutput(' ');
+ }
+
+ /**
+ * Generic method to acquire a hub-id. On first run this generates a new one
+ * based on many pseudo-random data. On any later run, unless the id
+ * got not removed from database, it will be restored from the database.
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
+ // Is there a node id?
+ if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
+ // Get the node id from result and set it
+ $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
+
+ // Output message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
+ } else {
+ // Get an RNG instance
+ $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+
+ // Generate a pseudo-random string
+ $randomString = $rngInstance->randomString(255);
+
+ // Hash and encrypt the string so we become a node id (also documented as "hub id")
+ $this->setNodeId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
+
+ // Register the node id with our wrapper
+ $this->getWrapperInstance()->registerNodeId($this, $this->getRequestInstance());
+
+ // Output message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . '');
+ }
+ }
+
+ /**
+ * Generates a session id which will be sent to the other hubs and peers
+ *
+ * @return void
+ */
+ public function bootstrapGenerateSessionId () {
+ // Now get a search criteria instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for the node number one which is hard-coded the default
+ $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
+ $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $this->getRequestInstance()->getRequestElement('mode'));
+ $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID , $this->getNodeId());
+ $searchInstance->setLimit(1);
+
+ // Remember it for later usage
+ $this->setSearchInstance($searchInstance);
+
+ // Get a random string
+ $randomString = $this->generateRamdomString(255);
+
+ // Hash and encrypt the string so we become a "node id" aka Hub-Id
+ $this->setSessionId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
+
+ // Register the node id with our wrapper
+ $this->getWrapperInstance()->registerSessionId($this, $this->getRequestInstance(), $searchInstance);
+
+ // Output message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
+
+ // Change the state because the node has aquired a session id
+ $this->getStateInstance()->nodeGeneratedSessionId();
+ }
+
+ /**
+ * Generate a private key for en-/decryption
+ *
+ * @return void
+ */
+ public function bootstrapGeneratePrivateKey () {
+ // Is it valid?
+ if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
+ // Is the element set?
+ if (is_null($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))) {
+ /*
+ * Auto-generate the private key for e.g. out-dated database
+ * "tables". This allows a smooth update for the underlaying
+ * database table.
+ */
+ $this->generatePrivateKeyAndHash($this->getSearchInstance());
+ } else {
+ // Get the node id from result and set it
+ $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY)));
+ $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH));
+
+ // Output message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . '');
+ }
+ } else {
+ /*
+ * Generate it in a private method (no confusion with 'private
+ * method access' and 'private key' here! ;-)).
+ */
+ $this->generatePrivateKeyAndHash($this->getSearchInstance());
+ }
+ }
+
+ /**
+ * Adds hub data elements to a given dataset instance
+ *
+ * @param $criteriaInstance An instance of a storeable criteria
+ * @param $requestInstance An instance of a Requestable class
+ * @return void
+ */
+ public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
+ // Make sure the request instance is set as it is not optional.
+ assert($requestInstance instanceof Requestable);
+
+ // Add node number and type
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $requestInstance->getRequestElement('mode'));
+
+ // Add the node id
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());
+
+ // Add the session id if acquired
+ if ($this->getSessionId() != '') {
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId());
+ } // END - if
+
+ // Add the private key if acquired
+ if ($this->getPrivateKey() != '') {
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey()));
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash());
+ } // END - if
+
+ // Add own external and internal addresses as UNLs
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, HubTools::determineOwnInternalAddress());
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL, HubTools::determineOwnExternalAddress());
+ }
+
+ /**
+ * Updates a given field with new value
+ *
+ * @param $fieldName Field to update
+ * @param $fieldValue New value to store
+ * @return void
+ * @throws DatabaseUpdateSupportException If this class does not support database updates
+ * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
+ */
+ public function updateDatabaseField ($fieldName, $fieldValue) {
+ // Unfinished
+ $this->partialStub('Unfinished!');
+ return;
+
+ // Get a critieria instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Add search criteria
+ $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+ $searchInstance->setLimit(1);
+
+ // Now get another criteria
+ $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
+
+ // Add criteria entry which we shall update
+ $updateInstance->addCriteria($fieldName, $fieldValue);
+
+ // Add the search criteria for searching for the right entry
+ $updateInstance->setSearchInstance($searchInstance);
+
+ // Set wrapper class name
+ $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
+
+ // Remember the update in database result
+ $this->getResultInstance()->add2UpdateQueue($updateInstance);
+ }
+
+ /**
+ * Announces this hub to the upper (bootstrap or list) hubs. After this is
+ * 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
+ * @throws NodeAlreadyAnnouncedException If this hub is already announced
+ * @todo Change the first if() block to check for a specific state
+ */
+ public function announceToUpperNodes (Taskable $taskInstance) {
+ // Is this hub node announced?
+ if ($this->hubIsAnnounced === TRUE) {
+ // Already announced!
+ throw new NodeAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
+ } // END - if
+
+ // Debug output
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
+
+ // Get a helper instance
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_helper_class');
+
+ // Load the announcement descriptor
+ $helperInstance->loadDescriptorXml($this);
+
+ // Compile all variables
+ $helperInstance->getTemplateInstance()->compileConfigInVariables();
+
+ // "Publish" the descriptor by sending it to the bootstrap/list nodes
+ $helperInstance->sendPackage($this);
+
+ // Change the state, this should be the last line except debug output
+ $this->getStateInstance()->nodeAnnouncingToUpperHubs();
+
+ // Debug output
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-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
+ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
+
+ // Get a helper instance
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('node_self_connect_helper_class', array($this));
+
+ // Load the descriptor (XML) file
+ $helperInstance->loadDescriptorXml($this);
+
+ // Compile all variables
+ $helperInstance->getTemplateInstance()->compileConfigInVariables();
+
+ // And send the package away
+ $helperInstance->sendPackage($this);
+
+ // Debug output
+ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: FINISHED');
+ }
+
+ /**
+ * Activates the hub by doing some final preparation and setting
+ * $hubIsActive to TRUE.
+ *
+ * @param $requestInstance A Requestable class
+ * @param $responseInstance A Responseable class
+ * @return void
+ */
+ public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
+ // Checks whether a listener is still active and shuts it down if one
+ // is still listening.
+ if (($this->determineIfListenerIsActive()) && ($this->isNodeActive())) {
+ // Shutdown them down before they can hurt anything
+ $this->shutdownListenerPool();
+ } // END - if
+
+ // Get the controller here
+ $controllerInstance = Registry::getRegistry()->getInstance('controller');
+
+ // Run all filters for the hub activation
+ $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
+
+ // ----------------------- Last step from here ------------------------
+ // Activate the hub. This is ALWAYS the last step in this method
+ $this->getStateInstance()->nodeIsActivated();
+ // ---------------------- Last step until here ------------------------
+ }
+
+ /**
+ * Initializes the listener pool (class)
+ *
+ * @return void
+ */
+ public function initializeListenerPool () {
+ // Debug output
+ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: START');
+
+ // Get a new pool instance
+ $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)));
+
+ // Get an instance of the low-level listener
+ $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this));
+
+ // Setup address and port
+ $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
+
+ /*
+ * All nodes can now use the same configuration entry because it can be
+ * customized in config-local.php.
+ */
+ $listenerInstance->setListenPortByConfiguration('node_listen_port');
+
+ // Initialize the listener
+ $listenerInstance->initListener();
+
+ // Get a decorator class
+ $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_tcp_listener_class', array($listenerInstance));
+
+ // Add this listener to the pool
+ $this->getListenerPoolInstance()->addListener($decoratorInstance);
+
+ // Get a decorator class
+ $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
+
+ // Add this listener to the pool
+ $this->getListenerPoolInstance()->addListener($decoratorInstance);
+
+ // Get an instance of the low-level listener
+ $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this));
+
+ // Setup address and port
+ $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
+
+ /*
+ * All nodes can now use the same configuration entry because it can be
+ * customized in config-local.php.
+ */
+ $listenerInstance->setListenPortByConfiguration('node_listen_port');
+
+ // Initialize the listener
+ $listenerInstance->initListener();
+
+ // Get a decorator class
+ $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_udp_listener_class', array($listenerInstance));
+
+ // Add this listener to the pool
+ $this->getListenerPoolInstance()->addListener($decoratorInstance);
+
+ // Get a decorator class
+ $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
+
+ // Add this listener to the pool
+ $this->getListenerPoolInstance()->addListener($decoratorInstance);
+
+ // Debug output
+ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: FINISHED.');
+ }
+
+ /**
+ * Getter for isActive attribute
+ *
+ * @return $isActive Whether the hub is active
+ */
+ public final function isNodeActive () {
+ return $this->isActive;
+ }
+
+ /**
+ * Enables (default) or disables isActive flag
+ *
+ * @param $isActive Whether the hub is active
+ * @return void
+ */
+ public final function enableIsActive ($isActive = TRUE) {
+ $this->isActive = (bool) $isActive;
+ }
+
+ /**
+ * Checks whether this node accepts announcements
+ *
+ * @return $acceptAnnouncements Whether this node accepts announcements
+ */
+ public final function isAcceptingAnnouncements () {
+ // Check it (this node must be active and not shutdown!)
+ $acceptAnnouncements = (($this->acceptAnnouncements === TRUE) && ($this->isNodeActive()));
+
+ // Return it
+ return $acceptAnnouncements;
+ }
+
+ /**
+ * Checks whether this node accepts DHT bootstrap requests
+ *
+ * @return $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests
+ */
+ public final function isAcceptingDhtBootstrap () {
+ // Check it (this node must be active and not shutdown!)
+ $acceptDhtBootstrap = (($this->acceptDhtBootstrap === TRUE) && ($this->isNodeActive()));
+
+ // Return it
+ return $acceptDhtBootstrap;
+ }
+
+ /**
+ * Checks whether this node has attempted to announce itself
+ *
+ * @return $hasAnnounced Whether this node has attempted to announce itself
+ * @todo Add checking if this node has been announced to the sender node
+ */
+ public function ifNodeIsAnnouncing () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeIsAnnouncing(): state=' . $this->getStateInstance()->getStateName());
+
+ // Simply check the state of this node
+ $hasAnnounced = ($this->getStateInstance() instanceof NodeAnnouncingState);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeIsAnnouncing(): hasAnnounced=' . intval($hasAnnounced));
+
+ // Return it
+ return $hasAnnounced;
+ }
+
+ /**
+ * Checks whether this node has attempted to announce itself and completed it
+ *
+ * @return $hasAnnouncementCompleted Whether this node has attempted to announce itself and completed it
+ * @todo Add checking if this node has been announced to the sender node
+ */
+ public function ifNodeHasAnnouncementCompleted () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): state=' . $this->getStateInstance()->getStateName());
+
+ // Simply check the state of this node
+ $hasAnnouncementCompleted = ($this->getStateInstance() instanceof NodeAnnouncementCompletedState);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): hasAnnouncementCompleted=' . intval($hasAnnouncementCompleted));
+
+ // Return it
+ return $hasAnnouncementCompleted;
+ }
+
+ /**
+ * Enables whether this node accepts announcements
+ *
+ * @param $acceptAnnouncements Whether this node accepts announcements (default: TRUE)
+ * @return void
+ */
+ protected final function enableAcceptingAnnouncements ($acceptAnnouncements = TRUE) {
+ $this->acceptAnnouncements = $acceptAnnouncements;
+ }
+
+ /**
+ * Enables whether this node accepts DHT bootstrap requests
+ *
+ * @param $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests (default: TRUE)
+ * @return void
+ */
+ public final function enableAcceptDhtBootstrap ($acceptDhtBootstrap = TRUE) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...');
+ $this->acceptDhtBootstrap = $acceptDhtBootstrap;
+ }
+
+ /**
+ * Checks wether this node is accepting node-list requests
+ *
+ * @return $acceptsRequest Wether this node accepts node-list requests
+ */
+ public function isAcceptingNodeListRequests () {
+ /*
+ * Only 'regular' nodes does not accept such requests, checking
+ * HubRegularNode is faster, but if e.g. HubRegularI2PNode will be
+ * added then the next check will be TRUE.
+ */
+ $acceptsRequest = ((!$this instanceof HubRegularNode) && ($this->getRequestInstance()->getRequestElement('mode') != self::NODE_TYPE_REGULAR));
+
+ // Return it
+ return $acceptsRequest;
+ }
+
+ /**
+ * Determines an instance of a LocateableNode class
+ *
+ * @return $unlInstance An instance of a LocateableNode class for this node
+ */
+ public function determineUniversalNodeLocator () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Determine UNL based on this node:
+ // 1) Get discovery class
+ $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
+
+ // 2) "Determine" it
+ $unlInstance = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
+
+ // 3) Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unlInstance= ' . $unlInstance->__toString() . ' - EXIT!');
+ return $unlInstance;
+ }
+
+ /**
+ * "Getter" for an array of an instance of a LocateableNode class
+ *
+ * @return $unlData An array from an instance of a LocateableNode class for this node
+ */
+ public final function getUniversalNodeLocatorArray () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Get the Universal Node Locator (UNL) instance
+ $unlInstance = $this->determineUniversalNodeLocator();
+
+ // Make sure the instance is valid
+ if (!$unlInstance instanceof LocateableNode) {
+ // No valid instance, so better debug this
+ $this->debugBackTrace('unlInstance[' . gettype($unlInstance) . ']=' . $unlInstance);
+ } // END - if
+
+ // ... and the array from it
+ $unlData = $unlInstance->getUnlData();
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ return $unlData;
+ }
+
+ /**
+ * Updates/refreshes node data (e.g. status).
+ *
+ * @return void
+ * @todo Find more to do here
+ */
+ public function updateNodeData () {
+ // Set some dummy configuration entries, e.g. node_status
+ $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
+ }
+
+ /**
+ * Handles message answer by given data array
+ *
+ * @param $messageData A valid answer message data array
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @todo Handle thrown exception
+ */
+ public function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance) {
+ // Is it not empty?
+ assert(!empty($messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]));
+
+ // Construct configuration entry for handling class' name
+ $classConfigEntry = strtolower($messageData[NetworkPackage::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]) . '_handler_class';
+
+ // Try to get a class
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
+
+ // Handle it there
+ $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
+ }
+
+ /**
+ * "Getter" for an array of all accepted object types
+ *
+ * @return $objectList Array of all accepted object types
+ */
+ public function getListFromAcceptedObjectTypes () {
+ // Get registry instance
+ $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
+
+ // Get all entries
+ $objectList = $objectRegistryInstance->getEntries(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME);
+
+ // ... and return it
+ return $objectList;
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $nodeData An array with valid node data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $nodeData) {
+ // Add all data the array provides
+ foreach (NodeDistributedHashTableDatabaseWrapper::getAllElements() as $element) {
+ // Is the element there?
+ if (isset($nodeData[$element])) {
+ // Add it
+ $dataSetInstance->addCriteria($element, $nodeData[$element]);
+ } else {
+ // Output warning message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: addArrayToDataSet(): Element ' . $element . ' not found in nodeData array.');
+ }
+ } // END - foreac
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A hub-node class for the 'List' mode
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubListNode extends BaseHubNode implements NodeHelper, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this hub-node class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
+ */
+ public static final function createHubListNode (Requestable $requestInstance) {
+ // Get a new instance
+ $nodeInstance = new HubListNode();
+
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $nodeInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the node. This step does also apply provided
+ * command-line arguments stored in the request instance. The regular node
+ * should communicate with the bootstrap-nodes at this point.
+ *
+ * @return void
+ * @todo Implement more bootstrap steps
+ */
+ public function doBootstrapping () {
+ $this->partialStub();
+ }
+
+ /**
+ * Add some node-specific filters
+ *
+ * @return void
+ */
+ public function addExtraNodeFilters () {
+ // Get the application instance from registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Get the controller from the application
+ $controllerInstance = $applicationInstance->getControllerInstance();
+
+ // Self-announcement task
+ $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_announcement_task_filter'));
+
+ // @TODO Add some filters here
+ $this->partialStub('Add some filters here.');
+ }
+
+ /**
+ * Adds extra tasks to the given handler for this node
+ *
+ * @param $handlerInstance An instance of a HandleableTask class
+ * @return void
+ * @todo 0% done
+ */
+ public function addExtraTasks (HandleableTask $handlerInstance) {
+ $this->partialStub('Please add some tasks or empty this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A hub-node class for the 'Master' mode
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubMasterNode extends BaseHubNode implements NodeHelper, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this hub-node class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
+ */
+ public static final function createHubMasterNode (Requestable $requestInstance) {
+ // Get a new instance
+ $nodeInstance = new HubMasterNode();
+
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $nodeInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the node. This step does also apply provided
+ * command-line arguments stored in the request instance. The regular node
+ * should communicate with the bootstrap-nodes at this point.
+ *
+ * @return void
+ * @todo Implement this method
+ */
+ public function doBootstrapping () {
+ // Enable acceptance of announcements
+ $this->enableAcceptingAnnouncements();
+
+ // Do more steps
+ $this->partialStub('Please implement more boot-strapping steps!');
+ }
+
+ /**
+ * Add some node-specific filters
+ *
+ * @return void
+ */
+ public function addExtraNodeFilters () {
+ // Get the application instance from registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Get the controller from the application
+ $controllerInstance = $applicationInstance->getControllerInstance();
+
+ // Self-announcement task
+ $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_announcement_task_filter'));
+
+ // @TODO Add some filters here
+ $this->partialStub('Add some filters here.');
+ }
+
+ /**
+ * Adds extra tasks to the given handler for this node
+ *
+ * @param $handlerInstance An instance of a HandleableTask class
+ * @return void
+ * @todo 0% done
+ */
+ public function addExtraTasks (HandleableTask $handlerInstance) {
+ $this->partialStub('Please add some tasks or empty this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A hub-node class for the 'regular' mode
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubRegularNode extends BaseHubNode implements NodeHelper, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this hub-node class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
+ */
+ public static final function createHubRegularNode (Requestable $requestInstance) {
+ // Get a new instance
+ $nodeInstance = new HubRegularNode();
+
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $nodeInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the node. This step does also apply provided
+ * command-line arguments stored in the request instance. The regular node
+ * should communicate with the bootstrap-nodes at this point.
+ *
+ * @return void
+ * @todo Implement this method
+ */
+ public function doBootstrapping () {
+ $this->partialStub();
+ }
+
+ /**
+ * Add some node-specific filters
+ *
+ * @return void
+ */
+ public function addExtraNodeFilters () {
+ // Get the application instance from registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Get the controller from the application
+ $controllerInstance = $applicationInstance->getControllerInstance();
+
+ // Self-announcement task
+ $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_announcement_task_filter'));
+
+ // @TODO Add some filters here
+ $this->partialStub('Add some filters here.');
+ }
+
+ /**
+ * Adds extra tasks to the given handler for this node
+ *
+ * @param $handlerInstance An instance of a HandleableTask class
+ * @return void
+ * @todo 0% done
+ */
+ public function addExtraTasks (HandleableTask $handlerInstance) {
+ $this->partialStub('Please add some tasks or empty this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A PackageAssembler class to assemble a package content stream fragemented
+ * by PackageFragmenter back to a raw package data array.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageAssembler extends BaseHubSystem implements Assembler, Registerable, Visitable {
+ /**
+ * Name for stacker holding raw data of multiple messages
+ */
+ const STACKER_NAME_MULTIPLE_MESSAGE = 'multiple_message';
+
+ /**
+ * Pending data
+ */
+ private $pendingData = '';
+
+ /**
+ * Private call-back methods
+ */
+ private $callbacks = array();
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return $assemblerInstance An instance of an Assembler class
+ */
+ public static final function createPackageAssembler (Receivable $packageInstance) {
+ // Get new instance
+ $assemblerInstance = new PackageAssembler();
+
+ // Set package instance here
+ $assemblerInstance->setPackageInstance($packageInstance);
+
+ // Create an instance of a raw data input stream
+ $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class');
+
+ // And set it
+ $assemblerInstance->setInputStreamInstance($streamInstance);
+
+ // Now get a chunk handler instance
+ $handlerInstance = ChunkHandlerFactory::createChunkHandlerInstance();
+
+ // Set handler instance
+ $assemblerInstance->setHandlerInstance($handlerInstance);
+
+ // Get stacker instance
+ $stackInstance = ObjectFactory::createObjectByConfiguredName('multiple_message_stacker_class');
+
+ // Initialize the only one stack
+ $stackInstance->initStack(self::STACKER_NAME_MULTIPLE_MESSAGE);
+
+ // And add it
+ $assemblerInstance->setStackInstance($stackInstance);
+
+ // Return the prepared instance
+ return $assemblerInstance;
+ }
+
+ /**
+ * Checks whether the input buffer (stacker to be more preceise) is empty.
+ *
+ * @return $isInputBufferEmpty Whether the input buffer is empty
+ */
+ private function ifInputBufferIsEmpty () {
+ // Check it
+ $isInputBufferEmpty = $this->getPackageInstance()->getStackInstance()->isStackEmpty(NetworkPackage::STACKER_NAME_DECODED_HANDLED);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: isInputBufferEmpty=' . intval($isInputBufferEmpty));
+
+ // Return it
+ return $isInputBufferEmpty;
+ }
+
+ /**
+ * Checks whether given package content is completed (start/end markers are found)
+ *
+ * @param $packageContent An array with two elements: 'raw_data' and 'error_code'
+ * @return $isCompleted Whether the given package content is completed
+ */
+ private function isPackageContentCompleted (array $packageContent) {
+ // Check both
+ $isCompleted = $this->ifStartEndMarkersSet($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]);
+
+ // Return status
+ return $isCompleted;
+ }
+
+ /**
+ * Assembles the content from $packageContent. This method does only
+ * initialize the whole process by creating a call-back which will then
+ * itself (99.9% of all cases) "explode" the decoded data stream and add
+ * it to a chunk assembler queue.
+ *
+ * If the call-back method or this would attempt to assemble the package
+ * chunks and (maybe) re-request some chunks from the sender, this would
+ * take to much time and therefore slow down this node again.
+ *
+ * @param $packageContent An array with two elements: 'raw_data' and 'error_code'
+ * @return void
+ * @throws UnsupportedPackageCodeHandlerException If the package code handler is not implemented
+ */
+ public function chunkPackageContent (array $packageContent) {
+ // Validate the package content array again
+ assert(
+ (isset($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA])) &&
+ (isset($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]))
+ );
+
+ // Construct call-back name from package error code
+ $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]] = 'handlePackageBy' . self::convertToClassName($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]);
+
+ // Abort if the call-back method is not there
+ if (!method_exists($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]])) {
+ // Throw an exception
+ throw new UnsupportedPackageCodeHandlerException(array($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]], $packageContent), BaseListener::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER);
+ } // END - if
+
+ // Call it back
+ call_user_func(array($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]]), $packageContent);
+ }
+
+ /**************************************************************************
+ * Call-back methods for above method *
+ **************************************************************************/
+
+ /**
+ * Call-back handler to handle unhandled package data. This method
+ * "explodes" the string with the chunk separator from PackageFragmenter
+ * class, does some low checks on it and feeds it into another queue for
+ * verification and re-request for bad chunks.
+ *
+ * @param $packageContent An array with two elements: 'raw_data' and 'error_code'
+ * @return void
+ */
+ private function handlePackageByUnhandledPackage (array $packageContent) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: packageData[' . BaseRawDataHandler::PACKAGE_RAW_DATA . ']=' . $packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]);
+
+ // Check for some conditions
+ if ((!$this->ifInputBufferIsEmpty()) || (!$this->isPackageContentCompleted($packageContent))) {
+ // Last chunk is not valid, so wait for more
+ $this->pendingData .= $packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA];
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Partial data received. Waiting for more ... ( ' . strlen($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]) . ' bytes)');
+ } else {
+ // Debug message
+ //* DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ': packageContent=' . print_r($packageContent, TRUE) . ',chunks='.print_r($chunks, TRUE));
+ }
+ }
+
+ /**
+ * Checks whether the assembler's pending data is empty which means it has
+ * no pending data left for handling ... ;-)
+ *
+ * @return $ifPendingDataIsEmpty Whether pending data is empty
+ */
+ public function isPendingDataEmpty () {
+ // A simbple check
+ $ifPendingDataIsEmpty = empty($this->pendingData);
+
+ // Return it
+ return $ifPendingDataIsEmpty;
+ }
+
+ /**
+ * Checks whether the assembler has multiple messages pending
+ *
+ * @return $isPending Whether the assembler has multiple messages pending
+ */
+ public function ifMultipleMessagesPending () {
+ // Determine it
+ $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_MULTIPLE_MESSAGE));
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ': isPending=' . intval($isPending));
+ return $isPending;
+ }
+
+ /**
+ * Handles the assembler's pending data
+ *
+ * @return void
+ */
+ public function handlePendingData () {
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to decode ' . strlen($this->pendingData) . ' Bytes of pending data. pendingData=' . $this->pendingData);
+
+ // Assert on condition
+ assert(!$this->isPendingDataEmpty());
+
+ // No markers set?
+ if (!$this->ifStartEndMarkersSet($this->pendingData)) {
+ // This will cause an assertition in next call, so simply wait for more data
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Pending data of ' . strlen($this->pendingData) . ' Bytes are incomplete, waiting for more ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: this->pendingData=' . $this->pendingData);
+ return;
+ } elseif (substr_count($this->pendingData, BaseRawDataHandler::STREAM_START_MARKER) > 1) {
+ /*
+ * Multiple messages found, so split off first message as the input
+ * stream can only handle one message per time.
+ */
+ foreach (explode(BaseRawDataHandler::STREAM_START_MARKER, $this->pendingData) as $message) {
+ // Prepend start marker again as it is needed to decode the message.
+ $message = BaseRawDataHandler::STREAM_START_MARKER . $message;
+
+ // Push it on stack
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_MULTIPLE_MESSAGE, $message);
+ } // END - foreach
+
+ // Clear pending data
+ $this->clearPendingData();
+
+ // ... and exit here
+ return;
+ }
+
+ // Init fake array
+ $packageContent = array(
+ BaseRawDataHandler::PACKAGE_RAW_DATA => $this->getInputStreamInstance()->streamData($this->pendingData),
+ BaseRawDataHandler::PACKAGE_ERROR_CODE => BaseRawDataHandler::SOCKET_ERROR_UNHANDLED
+ );
+
+ /*
+ * Clear pending data as it has been processed and will be handled some
+ * lines below.
+ */
+ $this->clearPendingData();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Last block of partial data received. A total of ' . strlen($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]) . ' bytes has been received.');
+
+ // Make sure last CHUNK_SEPARATOR is not there
+ if (substr($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA], -1, 1) == PackageFragmenter::CHUNK_SEPARATOR) {
+ // Remove it
+ $packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA] = substr($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA], 0, -1);
+ } // END - if
+
+ /*
+ * "explode" the string from 'raw_data' with chunk separator to get an
+ * array of chunks. These chunks must then be verified by their
+ * checksums. Also the final chunk must be handled.
+ */
+ $chunks = explode(PackageFragmenter::CHUNK_SEPARATOR, $packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]);
+
+ // Add all chunks because the last final chunk is found
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to add ' . count($chunks) . ' to chunk handler ...');
+ $this->getHandlerInstance()->addAllChunksWithFinal($chunks);
+ }
+
+ /**
+ * Handles multiple messages.
+ *
+ * @return void
+ */
+ public function handleMultipleMessages () {
+ // Assert on condition
+ assert($this->ifMultipleMessagesPending());
+ assert($this->isPendingDataEmpty());
+
+ // "Pop" next entry from stack and set it as new pending data
+ $this->pendingData = $this->getStackInstance()->popNamed(self::STACKER_NAME_MULTIPLE_MESSAGE);
+
+ // And handle it
+ $this->handlePendingData();
+ }
+
+ /**
+ * Accepts the visitor to process the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit the assembler
+ $visitorInstance->visitAssembler($this);
+ }
+
+ /**
+ * Clears pending data
+ *
+ * @return void
+ */
+ public function clearPendingData () {
+ // Clear it
+ $this->pendingData = '';
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A NetworkPackage class. This class implements Deliverable and Receivable
+ * because all network packages should be deliverable to other nodes and
+ * receivable from other nodes. It further provides methods for reading raw
+ * content from template engines and feeding it to the stacker for undeclared
+ * packages.
+ *
+ * The factory method requires you to provide a compressor class (which must
+ * implement the Compressor interface). If you don't want any compression (not
+ * adviceable due to increased network load), please use the NullCompressor
+ * class and encode it with BASE64 for a more error-free transfer over the
+ * Internet.
+ *
+ * For performance reasons, this class should only be instanciated once and then
+ * used as a "pipe-through" class.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Needs to add functionality for handling the object's type
+ *
+ * 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 NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, Registerable, Visitable {
+ /**
+ * Package mask for compressing package data:
+ * 0: Compressor extension
+ * 1: Raw package data
+ * 2: Tags, seperated by semicolons, no semicolon is required if only one tag is needed
+ * 3: Checksum
+ * 0 1 2 3
+ */
+ const PACKAGE_MASK = '%s%s%s%s%s%s%s';
+
+ /**
+ * Separator for the above mask
+ */
+ const PACKAGE_MASK_SEPARATOR = '^';
+
+ /**
+ * Size of an array created by invoking
+ * explode(NetworkPackage::PACKAGE_MASK_SEPARATOR, $content).
+ */
+ const PACKAGE_CONTENT_ARRAY_SIZE = 4;
+
+ /**
+ * Separator for checksum
+ */
+ const PACKAGE_CHECKSUM_SEPARATOR = '_';
+
+ /**
+ * Array indexes for above mask, start with zero
+ */
+ const INDEX_COMPRESSOR_EXTENSION = 0;
+ const INDEX_PACKAGE_DATA = 1;
+ const INDEX_TAGS = 2;
+ const INDEX_CHECKSUM = 3;
+
+ /**
+ * Array indexes for raw package array
+ */
+ const INDEX_PACKAGE_SENDER = 0;
+ const INDEX_PACKAGE_RECIPIENT = 1;
+ const INDEX_PACKAGE_CONTENT = 2;
+ const INDEX_PACKAGE_STATUS = 3;
+ const INDEX_PACKAGE_HASH = 4;
+ const INDEX_PACKAGE_PRIVATE_KEY_HASH = 5;
+
+ /**
+ * Size of the decoded data array
+ */
+ const DECODED_DATA_ARRAY_SIZE = 6;
+
+ /**
+ * Named array elements for decoded package content
+ */
+ const PACKAGE_CONTENT_EXTENSION = 'compressor';
+ const PACKAGE_CONTENT_MESSAGE = 'message';
+ const PACKAGE_CONTENT_TAGS = 'tags';
+ const PACKAGE_CONTENT_CHECKSUM = 'checksum';
+ const PACKAGE_CONTENT_SENDER = 'sender';
+ const PACKAGE_CONTENT_HASH = 'hash';
+ const PACKAGE_CONTENT_PRIVATE_KEY_HASH = 'pkhash';
+
+ /**
+ * Named array elements for package data
+ */
+ const PACKAGE_DATA_SENDER = 'sender';
+ const PACKAGE_DATA_RECIPIENT = 'recipient';
+ const PACKAGE_DATA_CONTENT = 'content';
+ const PACKAGE_DATA_STATUS = 'status';
+ const PACKAGE_DATA_HASH = 'hash';
+ const PACKAGE_DATA_PRIVATE_KEY_HASH = 'pkhash';
+
+ /**
+ * All package status
+ */
+ const PACKAGE_STATUS_NEW = 'new';
+ const PACKAGE_STATUS_FAILED = 'failed';
+ const PACKAGE_STATUS_DECODED = 'decoded';
+ const PACKAGE_STATUS_FAKED = 'faked';
+
+ /**
+ * Constants for message data array
+ */
+ const MESSAGE_ARRAY_DATA = 'message_data';
+ const MESSAGE_ARRAY_TYPE = 'message_type';
+ const MESSAGE_ARRAY_SENDER = 'message_sender';
+ const MESSAGE_ARRAY_HASH = 'message_hash';
+ const MESSAGE_ARRAY_TAGS = 'message_tags';
+
+ /**
+ * Generic answer status field
+ */
+
+ /**
+ * Tags separator
+ */
+ const PACKAGE_TAGS_SEPARATOR = ';';
+
+ /**
+ * Raw package data separator
+ */
+ const PACKAGE_DATA_SEPARATOR = '#';
+
+ /**
+ * Separator for more than one recipient
+ */
+ const PACKAGE_RECIPIENT_SEPARATOR = ':';
+
+ /**
+ * Network target (alias): 'upper nodes'
+ */
+ const NETWORK_TARGET_UPPER = 'upper';
+
+ /**
+ * Network target (alias): 'self'
+ */
+ const NETWORK_TARGET_SELF = 'self';
+
+ /**
+ * Network target (alias): 'dht'
+ */
+ const NETWORK_TARGET_DHT = 'dht';
+
+ /**
+ * TCP package size in bytes
+ */
+ const TCP_PACKAGE_SIZE = 512;
+
+ /**************************************************************************
+ * Stacker for out-going packages *
+ **************************************************************************/
+
+ /**
+ * Stacker name for "undeclared" packages
+ */
+ const STACKER_NAME_UNDECLARED = 'package_undeclared';
+
+ /**
+ * Stacker name for "declared" packages (which are ready to send out)
+ */
+ const STACKER_NAME_DECLARED = 'package_declared';
+
+ /**
+ * Stacker name for "out-going" packages
+ */
+ const STACKER_NAME_OUTGOING = 'package_outgoing';
+
+ /**************************************************************************
+ * Stacker for incoming packages *
+ **************************************************************************/
+
+ /**
+ * Stacker name for "incoming" decoded raw data
+ */
+ const STACKER_NAME_DECODED_INCOMING = 'package_decoded_data';
+
+ /**
+ * Stacker name for handled decoded raw data
+ */
+ const STACKER_NAME_DECODED_HANDLED = 'package_handled_decoded';
+
+ /**
+ * Stacker name for "chunked" decoded raw data
+ */
+ const STACKER_NAME_DECODED_CHUNKED = 'package_chunked_decoded';
+
+ /**************************************************************************
+ * Stacker for incoming messages *
+ **************************************************************************/
+
+ /**
+ * Stacker name for new messages
+ */
+ const STACKER_NAME_NEW_MESSAGE = 'package_new_message';
+
+ /**
+ * Stacker name for processed messages
+ */
+ const STACKER_NAME_PROCESSED_MESSAGE = 'package_processed_message';
+
+ /**************************************************************************
+ * Stacker for raw data handling *
+ **************************************************************************/
+
+ /**
+ * Stacker for outgoing data stream
+ */
+ 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 *
+ **************************************************************************/
+ const PROTOCOL_TCP = 'TCP';
+ const PROTOCOL_UDP = 'UDP';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $compressorInstance A Compressor instance for compressing the content
+ * @return $packageInstance An instance of a Deliverable class
+ */
+ public static final function createNetworkPackage (Compressor $compressorInstance) {
+ // Get new instance
+ $packageInstance = new NetworkPackage();
+
+ // Now set the compressor instance
+ $packageInstance->setCompressorInstance($compressorInstance);
+
+ /*
+ * We need to initialize a stack here for our packages even for those
+ * which have no recipient address and stamp... ;-) This stacker will
+ * also be used for incoming raw data to handle it.
+ */
+ $stackInstance = ObjectFactory::createObjectByConfiguredName('network_package_stacker_class');
+
+ // At last, set it in this class
+ $packageInstance->setStackInstance($stackInstance);
+
+ // Init all stacker
+ $packageInstance->initStacks();
+
+ // Get a visitor instance for speeding up things and set it
+ $visitorInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_monitor_visitor_class');
+ $packageInstance->setVisitorInstance($visitorInstance);
+
+ // Get crypto instance and set it, too
+ $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+ $packageInstance->setCryptoInstance($cryptoInstance);
+
+ // Get a singleton package assembler instance from factory and set it here, too
+ $assemblerInstance = PackageAssemblerFactory::createAssemblerInstance($packageInstance);
+ $packageInstance->setAssemblerInstance($assemblerInstance);
+
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Get pool instance from node
+ $poolInstance = $nodeInstance->getListenerPoolInstance();
+
+ // And set it here
+ $packageInstance->setListenerPoolInstance($poolInstance);
+
+ // Return the prepared instance
+ return $packageInstance;
+ }
+
+ /**
+ * Initialize all stackers
+ *
+ * @param $forceReInit Whether to force reinitialization of all stacks
+ * @return void
+ */
+ protected function initStacks ($forceReInit = FALSE) {
+ // Initialize all
+ $this->getStackInstance()->initStacks(array(
+ self::STACKER_NAME_UNDECLARED,
+ self::STACKER_NAME_DECLARED,
+ self::STACKER_NAME_OUTGOING,
+ self::STACKER_NAME_DECODED_INCOMING,
+ self::STACKER_NAME_DECODED_HANDLED,
+ self::STACKER_NAME_DECODED_CHUNKED,
+ self::STACKER_NAME_NEW_MESSAGE,
+ self::STACKER_NAME_PROCESSED_MESSAGE,
+ self::STACKER_NAME_OUTGOING_STREAM
+ ), $forceReInit);
+ }
+
+ /**
+ * Determines private key hash from given session id
+ *
+ * @param $decodedData Array with decoded data
+ * @return $hash Private key's hash
+ */
+ private function determineSenderPrivateKeyHash (array $decodedData) {
+ // Get DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Ask DHT for session id
+ $senderData = $dhtInstance->findNodeLocalBySessionId($decodedData[self::PACKAGE_CONTENT_SENDER]);
+
+ // Is an entry found?
+ if (count($senderData) > 0) {
+ // Make sure the element 'private_key_hash' is there
+ //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderData=' . print_r($senderData, TRUE));
+ assert(isset($senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH]));
+
+ // Return it
+ return $senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH];
+ } // END - if
+
+ // Make sure the requested element is there
+ //* DEBUG-DIE */ die('decodedData=' . print_r($decodedData, TRUE));
+ assert(isset($decodedData[self::PACKAGE_CONTENT_PRIVATE_KEY_HASH]));
+
+ // There is no DHT entry so, accept the hash from decoded data
+ return $decodedData[self::PACKAGE_CONTENT_PRIVATE_KEY_HASH];
+ }
+
+ /**
+ * "Getter" for hash from given content
+ *
+ * @param $content Raw package content
+ * @return $hash Hash for given package content
+ */
+ private function getHashFromContent ($content) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
+
+ // Create the hash
+ // @TODO md5() is very weak, but it needs to be fast
+ $hash = md5(
+ $content .
+ self::PACKAGE_CHECKSUM_SEPARATOR .
+ $this->getSessionId() .
+ self::PACKAGE_CHECKSUM_SEPARATOR .
+ $this->getCompressorInstance()->getCompressorExtension()
+ );
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
+
+ // And return it
+ return $hash;
+ }
+
+ /**
+ * Checks whether the checksum (sometimes called "hash") is the same
+ *
+ * @param $decodedContent Package raw content
+ * @param $decodedData Whole raw package data array
+ * @return $isChecksumValid Whether the checksum is the same
+ */
+ private function isChecksumValid (array $decodedContent, array $decodedData) {
+ // Get checksum
+ $checksum = $this->getHashFromContentSessionId($decodedContent, $decodedData[self::PACKAGE_DATA_SENDER]);
+
+ // Is it the same?
+ $isChecksumValid = ($checksum == $decodedContent[self::PACKAGE_CONTENT_CHECKSUM]);
+
+ // Return it
+ return $isChecksumValid;
+ }
+
+ /**
+ * Change the package with given status in given stack
+ *
+ * @param $packageData Raw package data in an array
+ * @param $stackerName Name of the stacker
+ * @param $newStatus New status to set
+ * @return void
+ */
+ private function changePackageStatus (array $packageData, $stackerName, $newStatus) {
+ // Skip this for empty stacks
+ if ($this->getStackInstance()->isStackEmpty($stackerName)) {
+ // This avoids an exception after all packages has failed
+ return;
+ } // END - if
+
+ // Pop the entry (it should be it)
+ $nextData = $this->getStackInstance()->popNamed($stackerName);
+
+ // Compare both hashes
+ assert($nextData[self::PACKAGE_DATA_HASH] == $packageData[self::PACKAGE_DATA_HASH]);
+
+ // Temporary set the new status
+ $packageData[self::PACKAGE_DATA_STATUS] = $newStatus;
+
+ // And push it again
+ $this->getStackInstance()->pushNamed($stackerName, $packageData);
+ }
+
+ /**
+ * "Getter" for hash from given content and sender's session id
+ *
+ * @param $decodedContent Raw package content
+ * @param $sessionId Session id of the sender
+ * @return $hash Hash for given package content
+ */
+ public function getHashFromContentSessionId (array $decodedContent, $sessionId) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_EXTENSION]);
+
+ // Create the hash
+ // @TODO md5() is very weak, but it needs to be fast
+ $hash = md5(
+ $decodedContent[self::PACKAGE_CONTENT_MESSAGE] .
+ self::PACKAGE_CHECKSUM_SEPARATOR .
+ $sessionId .
+ self::PACKAGE_CHECKSUM_SEPARATOR .
+ $decodedContent[self::PACKAGE_CONTENT_EXTENSION]
+ );
+
+ // And return it
+ return $hash;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Delivering packages / raw data
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Declares the given raw package data by discovering recipients
+ *
+ * @param $packageData Raw package data in an array
+ * @return void
+ */
+ private function declareRawPackageData (array $packageData) {
+ // Make sure the required field is there
+ assert(isset($packageData[self::PACKAGE_DATA_RECIPIENT]));
+
+ /*
+ * We need to disover every recipient, just in case we have a
+ * multi-recipient entry like 'upper' is. 'all' may be a not so good
+ * target because it causes an overload on the network and may be
+ * abused for attacking the network with large packages.
+ */
+ $discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
+
+ // Discover all recipients, this may throw an exception
+ $discoveryInstance->discoverRecipients($packageData);
+
+ // Now get an iterator
+ $iteratorInstance = $discoveryInstance->getIterator();
+
+ // Make sure the iterator instance is valid
+ assert($iteratorInstance instanceof Iterator);
+
+ // Rewind back to the beginning
+ $iteratorInstance->rewind();
+
+ // ... and begin iteration
+ while ($iteratorInstance->valid()) {
+ // Get current entry
+ $currentRecipient = $iteratorInstance->current();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]);
+
+ // Set the recipient
+ $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient;
+
+ // Push the declared package to the next stack.
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData);
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package declared for recipient ' . $currentRecipient);
+
+ // Skip to next entry
+ $iteratorInstance->next();
+ } // END - while
+
+ /*
+ * The recipient list can be cleaned up here because the package which
+ * shall be delivered has already been added for all entries from the
+ * list.
+ */
+ $discoveryInstance->clearRecipients();
+ }
+
+ /**
+ * Delivers raw package data. In short, this will discover the raw socket
+ * resource through a discovery class (which will analyse the receipient of
+ * the package), register the socket with the connection (handler/helper?)
+ * instance and finally push the raw data on our outgoing queue.
+ *
+ * @param $packageData Raw package data in an array
+ * @return void
+ */
+ private function deliverRawPackageData (array $packageData) {
+ /*
+ * This package may become big, depending on the shared object size or
+ * delivered message size which shouldn't be so long (to save
+ * bandwidth). Because of the nature of the used protocol (TCP) we need
+ * to split it up into smaller pieces to fit it into a TCP frame.
+ *
+ * So first we need (again) a discovery class but now a protocol
+ * discovery to choose the right socket resource. The discovery class
+ * should take a look at the raw package data itself and then decide
+ * which (configurable!) protocol should be used for that type of
+ * package.
+ */
+ $discoveryInstance = SocketDiscoveryFactory::createSocketDiscoveryInstance();
+
+ // Now discover the right protocol
+ $socketResource = $discoveryInstance->discoverSocket($packageData, BaseConnectionHelper::CONNECTION_TYPE_OUTGOING);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' after discoverSocket() has been called.');
+
+ // Debug message
+ //* 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.');
+
+ // 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');
+
+ // And make sure it is valid
+ assert($helperInstance instanceof ConnectionHelper);
+
+ // Get connection info class
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($helperInstance->getProtocolName(), 'helper');
+
+ // Will the info instance with connection helper data
+ $infoInstance->fillWithConnectionHelperInformation($helperInstance);
+
+ // Is it not there?
+ if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($infoInstance, $socketResource))) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Registering socket ' . $socketResource . ' ...');
+
+ // Then register it
+ $registryInstance->registerSocket($infoInstance, $socketResource, $packageData);
+ } elseif (!$helperInstance->getStateInstance()->isPeerStateConnected()) {
+ // Is not connected, then we cannot send
+ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.');
+
+ // Shutdown the socket
+ $this->shutdownSocket($socketResource);
+ }
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.');
+
+ // Make sure the connection is up
+ $helperInstance->getStateInstance()->validatePeerStateConnected();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.');
+
+ // Enqueue it again on the out-going queue, the connection is up and working at this point
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageData);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' after pushNamed() has been called.');
+ }
+
+ /**
+ * Sends waiting packages
+ *
+ * @param $packageData Raw package data
+ * @return void
+ */
+ private function sendOutgoingRawPackageData (array $packageData) {
+ // Init sent bytes
+ $sentBytes = 0;
+
+ // Get the right connection instance
+ $infoInstance = SocketRegistryFactory::createSocketRegistryInstance()->getInfoInstanceFromPackageData($packageData);
+
+ // Test helper instance
+ assert($infoInstance instanceof ShareableInfo);
+
+ // Get helper instance
+ $helperInstance = $infoInstance->getHelperInstance();
+
+ // Some sanity-checks on the object
+ //* DEBUG-DIE: */ die('[' . __METHOD__ . ':' . __LINE__ . ']: p1=' . $infoInstance->getProtocolName() . ',p2=' . $helperInstance->getProtocolName() . ',infoInstance=' . print_r($infoInstance, TRUE));
+ assert($helperInstance instanceof ConnectionHelper);
+ assert($infoInstance->getProtocolName() == $helperInstance->getProtocolName());
+
+ // Is this connection still alive?
+ if ($helperInstance->isShuttedDown()) {
+ // This connection is shutting down
+ // @TODO We may want to do somthing more here?
+ return;
+ } // END - if
+
+ // Sent out package data
+ $helperInstance->sendRawPackageData($packageData);
+ }
+
+ /**
+ * Generates a secure hash for given raw package content and sender id
+ *
+ * @param $content Raw package data
+ * @param $senderId Sender id to generate a hash for
+ * @return $hash Hash as hex-encoded string
+ */
+ private function generatePackageHash ($content, $senderId) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: content()=' . strlen($content) . ',senderId=' . $senderId . ' - CALLED!');
+
+ // Is the feature enabled?
+ if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
+ // Feature is not enabled
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Feature "hubcoin_reward" not available, not generating package hash. Returning NULL ...');
+ return NULL;
+ } // END - if
+
+ // Fake array
+ $data = array(
+ self::PACKAGE_CONTENT_SENDER => $senderId,
+ self::PACKAGE_CONTENT_MESSAGE => $content,
+ self::PACKAGE_CONTENT_PRIVATE_KEY_HASH => ''
+ );
+
+ // Hash content and sender id together, use scrypt
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $senderId . ',content()=' . strlen($content));
+ $hash = FrameworkFeature::callFeature('hubcoin_reward', 'generateHash', array($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($data)));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash . ' - EXIT!');
+
+ // Return it
+ return $hash;
+ }
+
+ /**
+ * Checks whether the hash of given package data is 'valid', here that
+ * means it is the same or not.
+ *
+ * @param $decodedArray An array with 'decoded' (explode() was mostly called) data
+ * @return $isHashValid Whether the hash is valid
+ * @todo Unfinished area, hashes are currently NOT fully supported
+ */
+ private function isPackageHashValid (array $decodedArray) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: decodedArray=' . print_r($decodedArray, TRUE) . ' - CALLED!');
+
+ // Make sure the required array elements are there
+ assert(isset($decodedArray[self::PACKAGE_CONTENT_SENDER]));
+ assert(isset($decodedArray[self::PACKAGE_CONTENT_MESSAGE]));
+ assert(isset($decodedArray[self::PACKAGE_CONTENT_HASH]));
+
+ // Is the feature enabled?
+ if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
+ // Feature is not enabled, so hashes are always valid
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Feature "hubcoin_reward" not available, not checking hash. Returning TRUE ...');
+ return TRUE;
+ } // END - if
+
+ // Check validity
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $decodedArray[self::PACKAGE_CONTENT_SENDER] . ',message()=' . strlen($decodedArray[self::PACKAGE_CONTENT_MESSAGE]) . '),hash=' . $decodedArray[self::PACKAGE_CONTENT_HASH]);
+ //* DEBUG-DIE: */ die(__METHOD__ . ': decodedArray=' . print_r($decodedArray, TRUE));
+ $isHashValid = FrameworkFeature::callFeature('hubcoin_reward', 'checkHash', array($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_MESSAGE] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH]));
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: isHashValid=' . intval($isHashValid) . ' - EXIT!');
+ return $isHashValid;
+ }
+
+ /**
+ * "Enqueues" raw content into this delivery class by reading the raw content
+ * from given helper's template instance and pushing it on the 'undeclared'
+ * stack.
+ *
+ * @param $helperInstance An instance of a HubHelper class
+ * @return void
+ */
+ public function enqueueRawDataFromTemplate (HubHelper $helperInstance) {
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
+ // Get the raw content ...
+ $content = $helperInstance->getTemplateInstance()->getRawTemplateData();
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('content(' . strlen($content) . ')=' . $content);
+
+ // ... and compress it
+ $compressed = $this->getCompressorInstance()->compressStream($content);
+
+ // Add magic in front of it and hash behind it, including BASE64 encoding
+ $packageContent = sprintf(self::PACKAGE_MASK,
+ // 1.) Compressor's extension
+ $this->getCompressorInstance()->getCompressorExtension(),
+ // - separator
+ self::PACKAGE_MASK_SEPARATOR,
+ // 2.) Compressed raw package content, encoded with BASE64
+ base64_encode($compressed),
+ // - separator
+ self::PACKAGE_MASK_SEPARATOR,
+ // 3.) Tags
+ implode(self::PACKAGE_TAGS_SEPARATOR, $helperInstance->getPackageTags()),
+ // - separator
+ self::PACKAGE_MASK_SEPARATOR,
+ // 4.) Checksum
+ $this->getHashFromContent($compressed)
+ );
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': Enqueueing package for recipientType=' . $helperInstance->getRecipientType() . ' ...');
+
+ // Now prepare the temporary array and push it on the 'undeclared' stack
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array(
+ self::PACKAGE_DATA_SENDER => $this->getSessionId(),
+ self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(),
+ self::PACKAGE_DATA_CONTENT => $packageContent,
+ self::PACKAGE_DATA_STATUS => self::PACKAGE_STATUS_NEW,
+ self::PACKAGE_DATA_HASH => $this->generatePackageHash($content, $this->getSessionId()),
+ self::PACKAGE_DATA_PRIVATE_KEY_HASH => $this->getPrivateKeyHash(),
+ ));
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
+ }
+
+ /**
+ * Checks whether a package has been enqueued for delivery.
+ *
+ * @return $isEnqueued Whether a package is enqueued
+ */
+ public function isPackageEnqueued () {
+ // Check whether the stacker is not empty
+ $isEnqueued = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_UNDECLARED)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_UNDECLARED)));
+
+ // Return the result
+ return $isEnqueued;
+ }
+
+ /**
+ * Checks whether a package has been declared
+ *
+ * @return $isDeclared Whether a package is declared
+ */
+ public function isPackageDeclared () {
+ // Check whether the stacker is not empty
+ $isDeclared = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_DECLARED)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECLARED)));
+
+ // Return the result
+ return $isDeclared;
+ }
+
+ /**
+ * Checks whether a package should be sent out
+ *
+ * @return $isWaitingDelivery Whether a package is waiting for delivery
+ */
+ public function isPackageWaitingForDelivery () {
+ // Check whether the stacker is not empty
+ $isWaitingDelivery = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_OUTGOING)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_OUTGOING)));
+
+ // Return the result
+ 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->getStackInstance()->isStackInitialized(self::STACKER_NAME_OUTGOING_STREAM)) && (!$this->getStackInstance()->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).
+ * This allows that a single package is being delivered to multiple targets
+ * without enqueueing it for every target. If no target is provided or it
+ * can't be determined a NoTargetException is being thrown.
+ *
+ * @return void
+ * @throws NoTargetException If no target can't be determined
+ */
+ public function declareEnqueuedPackage () {
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
+ // Make sure this method isn't working if there is no package enqueued
+ if (!$this->isPackageEnqueued()) {
+ // This is not fatal but should be avoided
+ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: No raw package data waiting declaration, but ' . __METHOD__ . ' has been called!');
+ return;
+ } // END - if
+
+ /*
+ * Now there are for sure packages to deliver, so start with the first
+ * one.
+ */
+ $packageData = $this->getStackInstance()->popNamed(self::STACKER_NAME_UNDECLARED);
+
+ // Declare the raw package data for delivery
+ $this->declareRawPackageData($packageData);
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
+ }
+
+ /**
+ * Delivers the next declared package. Only one package per time will be sent
+ * because this may take time and slows down the whole delivery
+ * infrastructure.
+ *
+ * @return void
+ */
+ public function processDeclaredPackage () {
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
+ // Sanity check if we have packages declared
+ if (!$this->isPackageDeclared()) {
+ // This is not fatal but should be avoided
+ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: No package has been declared, but ' . __METHOD__ . ' has been called!');
+ return;
+ } // END - if
+
+ // Get the package
+ $packageData = $this->getStackInstance()->getNamed(self::STACKER_NAME_DECLARED);
+
+ // Assert on it
+ assert(isset($packageData[self::PACKAGE_DATA_RECIPIENT]));
+
+ // Try to deliver the package
+ try {
+ // And try to send it
+ $this->deliverRawPackageData($packageData);
+
+ // And remove it finally
+ $this->getStackInstance()->popNamed(self::STACKER_NAME_DECLARED);
+ } catch (UnexpectedStateException $e) {
+ // The state is not excepected (shall be 'connected')
+ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Caught ' . $e->__toString() . ',message=' . $e->getMessage());
+
+ // Mark the package with status failed
+ $this->changePackageStatus($packageData, self::STACKER_NAME_DECLARED, self::PACKAGE_STATUS_FAILED);
+ }
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
+ }
+
+ /**
+ * Sends waiting packages out for delivery
+ *
+ * @return void
+ */
+ public function sendWaitingPackage () {
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
+ // Sanity check if we have packages waiting for delivery
+ if (!$this->isPackageWaitingForDelivery()) {
+ // This is not fatal but should be avoided
+ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: No package is waiting for delivery, but ' . __METHOD__ . ' was called.');
+ return;
+ } // END - if
+
+ // Get the package
+ $packageData = $this->getStackInstance()->getNamed(self::STACKER_NAME_OUTGOING);
+
+ try {
+ // Now try to send it
+ $this->sendOutgoingRawPackageData($packageData);
+
+ // And remove it finally
+ $this->getStackInstance()->popNamed(self::STACKER_NAME_OUTGOING);
+ } catch (InvalidSocketException $e) {
+ // Output exception message
+ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package was not delivered: ' . $e->getMessage());
+
+ // Mark package as failed
+ $this->changePackageStatus($packageData, self::STACKER_NAME_OUTGOING, self::PACKAGE_STATUS_FAILED);
+ }
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
+ }
+
+ /**
+ * Sends out encoded data to a socket
+ *
+ * @return void
+ */
+ public function sendEncodedData () {
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
+ // Make sure there is pending encoded data
+ assert($this->isEncodedDataPending());
+
+ // Pop current data from stack
+ $encodedDataArray = $this->getStackInstance()->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->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Receiving packages / raw data
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Checks whether decoded raw data is pending
+ *
+ * @return $isPending Whether decoded raw data is pending
+ */
+ private function isRawDataPending () {
+ // Just return whether the stack is not empty
+ $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_INCOMING));
+
+ // Return the status
+ return $isPending;
+ }
+
+ /**
+ * Checks whether new raw package data has arrived at a socket
+ *
+ * @return $hasArrived Whether new raw package data has arrived for processing
+ */
+ public function isNewRawDataPending () {
+ // Visit the pool. This monitors the pool for incoming raw data.
+ $this->getListenerPoolInstance()->accept($this->getVisitorInstance());
+
+ // Check for new data arrival
+ $hasArrived = $this->isRawDataPending();
+
+ // Return the status
+ return $hasArrived;
+ }
+
+ /**
+ * Handles the incoming decoded raw data. This method does not "convert" the
+ * decoded data back into a package array, it just "handles" it and pushs it
+ * on the next stack.
+ *
+ * @return void
+ */
+ public function handleIncomingDecodedData () {
+ /*
+ * This method should only be called if decoded raw data is pending,
+ * so check it again.
+ */
+ if (!$this->isRawDataPending()) {
+ // This is not fatal but should be avoided
+ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: No raw (decoded?) data is pending, but ' . __METHOD__ . ' has been called!');
+ return;
+ } // END - if
+
+ // Very noisy debug message:
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Stacker size is ' . $this->getStackInstance()->getStackCount(self::STACKER_NAME_DECODED_INCOMING) . ' entries.');
+
+ // "Pop" the next entry (the same array again) from the stack
+ $decodedData = $this->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_INCOMING);
+
+ // Make sure both array elements are there
+ assert(
+ (is_array($decodedData)) &&
+ (isset($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA])) &&
+ (isset($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE]))
+ );
+
+ /*
+ * Also make sure the error code is SOCKET_ERROR_UNHANDLED because we
+ * only want to handle unhandled packages here.
+ */
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] . '(' . BaseRawDataHandler::SOCKET_ERROR_UNHANDLED . ')');
+ assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == BaseRawDataHandler::SOCKET_ERROR_UNHANDLED);
+
+ // Remove the last chunk SEPARATOR (because there is no need for it)
+ if (substr($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA], -1, 1) == PackageFragmenter::CHUNK_SEPARATOR) {
+ // It is there and should be removed
+ $decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA] = substr($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA], 0, -1);
+ } // END - if
+
+ // This package is "handled" and can be pushed on the next stack
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Pushing ' . strlen($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA]) . ' bytes to stack ' . self::STACKER_NAME_DECODED_HANDLED . ' ...');
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_HANDLED, $decodedData);
+ }
+
+ /**
+ * Adds raw decoded data from the given handler instance to this receiver
+ *
+ * @param $handlerInstance An instance of a Networkable class
+ * @return void
+ */
+ public function addRawDataToIncomingStack (Networkable $handlerInstance) {
+ /*
+ * Get the decoded data from the handler, this is an array with
+ * 'raw_data' and 'error_code' as elements.
+ */
+ $decodedData = $handlerInstance->getNextRawData();
+
+ // Very noisy debug message:
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: decodedData[' . gettype($decodedData) . ']=' . print_r($decodedData, TRUE));
+
+ // And push it on our stack
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_INCOMING, $decodedData);
+ }
+
+ /**
+ * Checks whether incoming decoded data is handled.
+ *
+ * @return $isHandled Whether incoming decoded data is handled
+ */
+ public function isIncomingRawDataHandled () {
+ // Determine if the stack is not empty
+ $isHandled = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_HANDLED));
+
+ // Return it
+ return $isHandled;
+ }
+
+ /**
+ * Checks whether the assembler has pending data left
+ *
+ * @return $isHandled Whether the assembler has pending data left
+ */
+ public function ifAssemblerHasPendingDataLeft () {
+ // Determine if the stack is not empty
+ $isHandled = (!$this->getAssemblerInstance()->isPendingDataEmpty());
+
+ // Return it
+ return $isHandled;
+ }
+
+ /**
+ * Checks whether the assembler has multiple packages pending
+ *
+ * @return $isPending Whether the assembler has multiple packages pending
+ */
+ public function ifMultipleMessagesPending () {
+ // Determine if the stack is not empty
+ $isPending = ($this->getAssemblerInstance()->ifMultipleMessagesPending());
+
+ // Return it
+ return $isPending;
+ }
+
+ /**
+ * Handles the attached assemler's pending data queue to be finally
+ * assembled to the raw package data back.
+ *
+ * @return void
+ */
+ public function handleAssemblerPendingData () {
+ // Handle it
+ $this->getAssemblerInstance()->handlePendingData();
+ }
+
+ /**
+ * Handles multiple messages.
+ *
+ * @return void
+ */
+ public function handleMultipleMessages () {
+ // Handle it
+ $this->getAssemblerInstance()->handleMultipleMessages();
+ }
+
+ /**
+ * Assembles incoming decoded data so it will become an abstract network
+ * package again. The assembler does later do it's job by an other task,
+ * not this one to keep best speed possible.
+ *
+ * @return void
+ */
+ public function assembleDecodedDataToPackage () {
+ // Make sure the raw decoded package data is handled
+ assert($this->isIncomingRawDataHandled());
+
+ // Get current package content (an array with two elements; see handleIncomingDecodedData() for details)
+ $packageContent = $this->getStackInstance()->getNamed(self::STACKER_NAME_DECODED_HANDLED);
+
+ // Assert on some elements
+ assert(
+ (is_array($packageContent)) &&
+ (isset($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA])) &&
+ (isset($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]))
+ );
+
+ // Start assembling the raw package data array by chunking it
+ $this->getAssemblerInstance()->chunkPackageContent($packageContent);
+
+ // Remove the package from 'handled_decoded' stack ...
+ $this->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_HANDLED);
+
+ // ... and push it on the 'chunked' stacker
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Pushing ' . strlen($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]) . ' bytes on stack ' . self::STACKER_NAME_DECODED_CHUNKED . ',packageContent=' . print_r($packageContent, TRUE));
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_CHUNKED, $packageContent);
+ }
+
+ /**
+ * Accepts the visitor to process the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - CALLED!');
+
+ // Visit the package
+ $visitorInstance->visitNetworkPackage($this);
+
+ // Then visit the assembler to handle multiple packages
+ $this->getAssemblerInstance()->accept($visitorInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - EXIT!');
+ }
+
+ /**
+ * Clears all stacks
+ *
+ * @return void
+ */
+ public function clearAllStacks () {
+ // Call the init method to force re-initialization
+ $this->initStacks(TRUE);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: All stacker have been re-initialized.');
+ }
+
+ /**
+ * Removes the first failed outoging package from the stack to continue
+ * with next one (it will never work until the issue is fixed by you).
+ *
+ * @return void
+ * @throws UnexpectedPackageStatusException If the package status is not 'failed'
+ * @todo This may be enchanced for outgoing packages?
+ */
+ public function removeFirstFailedPackage () {
+ // Get the package again
+ $packageData = $this->getStackInstance()->getNamed(self::STACKER_NAME_DECLARED);
+
+ // Is the package status 'failed'?
+ if ($packageData[self::PACKAGE_DATA_STATUS] != self::PACKAGE_STATUS_FAILED) {
+ // Not failed!
+ throw new UnexpectedPackageStatusException(array($this, $packageData, self::PACKAGE_STATUS_FAILED), BaseListener::EXCEPTION_UNEXPECTED_PACKAGE_STATUS);
+ } // END - if
+
+ // Remove this entry
+ $this->getStackInstance()->popNamed(self::STACKER_NAME_DECLARED);
+ }
+
+ /**
+ * "Decode" the package content into the same array when it was sent.
+ *
+ * @param $rawPackageContent The raw package content to be "decoded"
+ * @return $decodedData An array with 'sender', 'recipient', 'content' and 'status' elements
+ */
+ public function decodeRawContent ($rawPackageContent) {
+ // Use the separator '#' to "decode" it
+ $decodedArray = explode(self::PACKAGE_DATA_SEPARATOR, $rawPackageContent);
+
+ // Assert on count (should be always 3)
+ assert(count($decodedArray) == self::DECODED_DATA_ARRAY_SIZE);
+
+ /*
+ * Create 'decodedData' array with all assoziative array elements.
+ */
+ $decodedData = array(
+ self::PACKAGE_DATA_SENDER => $decodedArray[self::INDEX_PACKAGE_SENDER],
+ self::PACKAGE_DATA_RECIPIENT => $decodedArray[self::INDEX_PACKAGE_RECIPIENT],
+ self::PACKAGE_DATA_CONTENT => $decodedArray[self::INDEX_PACKAGE_CONTENT],
+ self::PACKAGE_DATA_STATUS => self::PACKAGE_STATUS_DECODED,
+ self::PACKAGE_DATA_HASH => $decodedArray[self::INDEX_PACKAGE_HASH],
+ self::PACKAGE_DATA_PRIVATE_KEY_HASH => $decodedArray[self::INDEX_PACKAGE_PRIVATE_KEY_HASH]
+ );
+
+ // And return it
+ return $decodedData;
+ }
+
+ /**
+ * Handles decoded data for this node by "decoding" the 'content' part of
+ * it. Again this method uses explode() for the "decoding" process.
+ *
+ * @param $decodedData An array with decoded raw package data
+ * @return void
+ * @throws InvalidDataChecksumException If the checksum doesn't match
+ */
+ public function handleRawData (array $decodedData) {
+ /*
+ * "Decode" the package's content by a simple explode() call, for
+ * details of the array elements, see comments for constant
+ * PACKAGE_MASK.
+ */
+ $decodedContent = explode(self::PACKAGE_MASK_SEPARATOR, $decodedData[self::PACKAGE_DATA_CONTENT]);
+
+ // Assert on array count for a very basic validation
+ assert(count($decodedContent) == self::PACKAGE_CONTENT_ARRAY_SIZE);
+
+ /*
+ * Convert the indexed array into an associative array. This is much
+ * better to remember than plain numbers, isn't it?
+ */
+ $decodedContent = array(
+ // Compressor's extension used to compress the data
+ self::PACKAGE_CONTENT_EXTENSION => $decodedContent[self::INDEX_COMPRESSOR_EXTENSION],
+ // Package data (aka "message") in BASE64-decoded form but still compressed
+ self::PACKAGE_CONTENT_MESSAGE => base64_decode($decodedContent[self::INDEX_PACKAGE_DATA]),
+ // Tags as an indexed array for "tagging" the message
+ self::PACKAGE_CONTENT_TAGS => explode(self::PACKAGE_TAGS_SEPARATOR, $decodedContent[self::INDEX_TAGS]),
+ // Checksum of the _decoded_ data
+ self::PACKAGE_CONTENT_CHECKSUM => $decodedContent[self::INDEX_CHECKSUM],
+ // Sender's id
+ self::PACKAGE_CONTENT_SENDER => $decodedData[self::PACKAGE_DATA_SENDER],
+ // Hash from decoded raw data
+ self::PACKAGE_CONTENT_HASH => $decodedData[self::PACKAGE_DATA_HASH],
+ // Hash of private key
+ self::PACKAGE_CONTENT_PRIVATE_KEY_HASH => $decodedData[self::PACKAGE_DATA_PRIVATE_KEY_HASH]
+ );
+
+ // Is the checksum valid?
+ if (!$this->isChecksumValid($decodedContent, $decodedData)) {
+ // Is not the same, so throw an exception here
+ throw new InvalidDataChecksumException(array($this, $decodedContent, $decodedData), BaseListener::EXCEPTION_INVALID_DATA_CHECKSUM);
+ } // END - if
+
+ /*
+ * The checksum is the same, then it can be decompressed safely. The
+ * original message is at this point fully decoded.
+ */
+ $decodedContent[self::PACKAGE_CONTENT_MESSAGE] = $this->getCompressorInstance()->decompressStream($decodedContent[self::PACKAGE_CONTENT_MESSAGE]);
+
+ // And push it on the next stack
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_NEW_MESSAGE, $decodedContent);
+ }
+
+ /**
+ * Checks whether a new message has arrived
+ *
+ * @return $hasArrived Whether a new message has arrived for processing
+ */
+ public function isNewMessageArrived () {
+ // Determine if the stack is not empty
+ $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_NEW_MESSAGE));
+
+ // Return it
+ return $hasArrived;
+ }
+
+ /**
+ * Handles newly arrived messages
+ *
+ * @return void
+ * @todo Implement verification of all sent tags here?
+ */
+ public function handleNewlyArrivedMessage () {
+ // Make sure there is at least one message
+ assert($this->isNewMessageArrived());
+
+ // Get it from the stacker, it is the full array with the decoded message
+ $decodedContent = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
+
+ // Generate the hash of comparing it
+ if (!$this->isPackageHashValid($decodedContent)) {
+ // Is not valid, so throw an exception here
+ exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . chr(10));
+ } // END - if
+
+ // Now get a filter chain back from factory with given tags array
+ $chainInstance = PackageFilterChainFactory::createChainByTagsArray($decodedContent[self::PACKAGE_CONTENT_TAGS]);
+
+ /*
+ * Process the message through all filters, note that all other
+ * elements from $decodedContent are no longer needed.
+ */
+ $chainInstance->processMessage($decodedContent, $this);
+
+ /*
+ * Post-processing of message data (this won't remote the message from
+ * the stack).
+ */
+ $chainInstance->postProcessMessage($this);
+ }
+
+ /**
+ * Checks whether a processed message is pending for "interpretation"
+ *
+ * @return $isPending Whether a processed message is pending
+ */
+ public function isProcessedMessagePending () {
+ // Check it
+ $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PROCESSED_MESSAGE));
+
+ // Return it
+ return $isPending;
+ }
+
+ /**
+ * Handle processed messages by "interpreting" the 'message_type' element
+ *
+ * @return void
+ */
+ public function handleProcessedMessage () {
+ // Get it from the stacker, it is the full array with the processed message
+ $messageArray = $this->getStackInstance()->popNamed(self::STACKER_NAME_PROCESSED_MESSAGE);
+
+ // Add type for later easier handling
+ $messageArray[self::MESSAGE_ARRAY_DATA][self::MESSAGE_ARRAY_TYPE] = $messageArray[self::MESSAGE_ARRAY_TYPE];
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: messageArray=' . print_r($messageArray, TRUE));
+
+ // Create a handler instance from given message type
+ $handlerInstance = MessageTypeHandlerFactory::createMessageTypeHandlerInstance($messageArray[self::MESSAGE_ARRAY_TYPE]);
+
+ // Handle message data
+ $handlerInstance->handleMessageData($messageArray[self::MESSAGE_ARRAY_DATA], $this);
+
+ // Post-handling of message data
+ $handlerInstance->postHandleMessageData($messageArray, $this);
+ }
+
+ /**
+ * Feeds the hash and sender (as recipient for the 'sender' reward) to the
+ * miner's queue, unless the message is not a "reward claim" message as this
+ * leads to an endless loop. You may wish to run the miner to get some
+ * reward ("Hubcoins") for "mining" this hash.
+ *
+ * @param $messageData Array with message data
+ * @return void
+ * @todo ~10% done?
+ */
+ public function feedHashToMiner (array $messageData) {
+ // Is the feature enabled?
+ if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
+ /*
+ * Feature is not enabled, don't feed the hash to the miner as it
+ *may be invalid.
+ */
+ return;
+ } // END - if
+
+ // Make sure the required elements are there
+ assert(isset($messageData[self::MESSAGE_ARRAY_SENDER]));
+ assert(isset($messageData[self::MESSAGE_ARRAY_HASH]));
+ assert(isset($messageData[self::MESSAGE_ARRAY_TAGS]));
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
+
+ // Resolve session id ('sender' is a session id) into node id
+ $nodeId = HubTools::resolveNodeIdBySessionId($messageData[self::MESSAGE_ARRAY_SENDER]);
+
+ // Is 'claim_reward' the message type?
+ if (in_array('claim_reward', $messageData[self::MESSAGE_ARRAY_TAGS])) {
+ /*
+ * Then don't feed this message to the miner as this causes an
+ * endless loop of mining.
+ */
+ return;
+ } // END - if
+
+ $this->partialStub('@TODO nodeId=' . $nodeId . ',messageData=' . print_r($messageData, TRUE));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A PackageFragmenter class to fragment package data into smaller chunks for
+ * delivery. This class calculates a final hash on the raw input data and
+ * fragments the data into smaller chunks after it has been encoded by a
+ * "outgoing encoding stream".
+ *
+ * All chunks are extended with a hash and a serial number to make it later
+ * easier to verify them and put them back in the right order and to, if
+ * required, request a re-delivery of an invalid chunk (e.g. hash didn't match).
+ * Also an "end-of-package" marker is being added as the last chunk to mark the
+ * end of of the whole package submission.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageFragmenter extends BaseHubSystem implements Fragmentable, Registerable {
+ /**
+ * Cached chunk size in bits
+ */
+ private $chunkSize = 0;
+
+ /**
+ * Array for chunks
+ */
+ private $chunks = array();
+
+ /**
+ * Array for chunk hashes
+ */
+ private $chunkHashes = array();
+
+ /**
+ * Array for chunk pointers
+ */
+ private $chunkPointers = array();
+
+ /**
+ * Array for processed packages
+ */
+ private $processedPackages = array();
+
+ /**
+ * Serial numbers (array key is final hash)
+ */
+ private $serialNumber = array();
+
+ /**
+ * Maximum possible serial number, "cache" for speeding up things
+ */
+ private $maxSerialNumber = 0;
+
+ /**
+ * Length of largest possible serial number
+ */
+ const MAX_SERIAL_LENGTH = 8;
+
+ /**
+ * Separator between chunk data, serial number and chunk hash
+ */
+ const CHUNK_DATA_HASH_SEPARATOR = '@';
+
+ /**
+ * SEPARATOR for all chunk hashes
+ */
+ const CHUNK_HASH_SEPARATOR = ';';
+
+ /**
+ * SEPARATOR between two chunks
+ */
+ const CHUNK_SEPARATOR = '|';
+
+ /**
+ * Identifier for hash chunk
+ */
+ const HASH_CHUNK_IDENTIFIER = 'HASH-CHUNK:';
+
+ /**
+ * Identifier for end-of-package marker
+ */
+ const END_OF_PACKAGE_IDENTIFIER = 'EOP:';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init this fragmenter
+ $this->initFragmenter();
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $fragmenterInstance An instance of a Fragmentable class
+ */
+ public static final function createPackageFragmenter () {
+ // Get new instance
+ $fragmenterInstance = new PackageFragmenter();
+
+ // Get a crypto instance and set it here
+ $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+ $fragmenterInstance->setCryptoInstance($cryptoInstance);
+
+ // Return the prepared instance
+ return $fragmenterInstance;
+ }
+
+ /**
+ * Initializes this fragmenter
+ *
+ * @return void
+ */
+ private function initFragmenter () {
+ // Load some configuration entries and "cache" them:
+ // - Chunk size in bits
+ $this->chunkSize = $this->getConfigInstance()->getConfigEntry('package_chunk_size');
+
+ // - Maximum serial number
+ $this->maxSerialNumber = $this->hex2dec(str_repeat('f', self::MAX_SERIAL_LENGTH));
+ }
+
+ /**
+ * Initializes the pointer for given final hash
+ *
+ * @param $finalHash Final hash to initialize pointer for
+ * @return void
+ */
+ private function initPointer ($finalHash) {
+ $this->chunkPointers[$finalHash] = 0;
+ }
+
+ /**
+ * "Getter" for processedPackages array index
+ *
+ * @param $packageData Raw package data array
+ * @return $index Array index for processedPackages
+ */
+ private function getProcessedPackagesIndex (array $packageData) {
+ return (
+ $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . NetworkPackage::PACKAGE_DATA_SEPARATOR .
+ $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . NetworkPackage::PACKAGE_DATA_SEPARATOR .
+ $packageData[NetworkPackage::PACKAGE_DATA_CONTENT] . NetworkPackage::PACKAGE_DATA_SEPARATOR
+ );
+ }
+
+ /**
+ * Checks whether the given package data is already processed by this fragmenter
+ *
+ * @param $packageData Raw package data array
+ * @return $isProcessed Whether the package has been fragmented
+ */
+ private function isPackageProcessed (array $packageData) {
+ // Get array index
+ $index = $this->getProcessedPackagesIndex($packageData);
+
+ // Is the array index there?
+ $isProcessed = (
+ (isset($this->processedPackages[$index]))
+ &&
+ ($this->processedPackages[$index] === TRUE)
+ );
+
+ // Return it
+ return $isProcessed;
+ }
+
+ /**
+ * Marks the given package data as processed by this fragmenter
+ *
+ * @param $packageData Raw package data array
+ * @return void
+ */
+ private function markPackageDataProcessed (array $packageData) {
+ // Remember it (until we may remove it)
+ $this->processedPackages[$this->getProcessedPackagesIndex($packageData)] = TRUE;
+ }
+
+ /**
+ * Getter for final hash from given package data
+ *
+ * @param $packageData Raw package data array
+ * @return $finalHash Final hash for package data
+ */
+ private function getFinalHashFromPackageData (array $packageData) {
+ // Make sure it is there
+ assert(isset($this->processedPackages[$this->getProcessedPackagesIndex($packageData)]));
+
+ // Return it
+ return $this->processedPackages[$this->getProcessedPackagesIndex($packageData)];
+ }
+
+ /**
+ * Get next chunk pointer for given final hash
+ *
+ * @param $finalHash Final hash to get current pointer for
+ */
+ private function getCurrentChunkPointer ($finalHash) {
+ // Is the final hash valid?
+ assert(strlen($finalHash) > 0);
+
+ // Is the pointer already initialized?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
+ assert(isset($this->chunkPointers[$finalHash]));
+
+ // Return it
+ return $this->chunkPointers[$finalHash];
+ }
+
+ /**
+ * Advance the chunk pointer for given final hash
+ *
+ * @param $finalHash Final hash to advance the pointer for
+ */
+ private function nextChunkPointer ($finalHash) {
+ // Is the pointer already initialized?
+ assert(isset($this->chunkPointers[$finalHash]));
+
+ // Count one up
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
+ $this->chunkPointers[$finalHash]++;
+ }
+
+ /**
+ * "Getter" for data chunk size of given hash.
+ *
+ * @param $hash Hash to substract it's length
+ * @return $dataChunkSize The chunk size
+ */
+ private function getDataChunkSizeFromHash ($hash) {
+ // Calculate real (data) chunk size
+ $dataChunkSize = (
+ // Real chunk size
+ ($this->chunkSize / 8) -
+ // Hash size
+ strlen($hash) -
+ // Length of sperators
+ (strlen(self::CHUNK_DATA_HASH_SEPARATOR) * 2) -
+ // Length of max serial number
+ self::MAX_SERIAL_LENGTH
+ );
+
+ // This should be larger than zero bytes
+ assert($dataChunkSize > 0);
+
+ // Return it
+ return $dataChunkSize;
+ }
+
+ /**
+ * Generates a hash from raw data
+ *
+ * @param $rawData Raw data bytes to hash
+ * @return $hash Hash from the raw data
+ * @todo Implement a way to send non-announcement packages with extra-salt
+ */
+ private function generateHashFromRawData ($rawData) {
+ /*
+ * Get the crypto instance and hash the data with no extra salt because
+ * the other peer doesn't have *this* peer's salt.
+ */
+ $hash = $this->getCryptoInstance()->hashString($rawData, '', FALSE);
+
+ // Return it
+ return $hash;
+ }
+
+ /**
+ * Appends an end-of-package chunk to the chunk list for given chunk and
+ * final hash. As of 23-March-2012 the format of this chunk will be as any
+ * regular one to keep things easy (KISS) in ChunkHandler class.
+ *
+ * @param $lastChunk Last chunk raw data
+ * @param $finalHash Final hash for raw (unencoded) data
+ * @return void
+ */
+ private function appendEndOfPackageChunk ($lastChunk, $finalHash) {
+ // Generate end-of-package marker
+ $chunkData =
+ self::END_OF_PACKAGE_IDENTIFIER .
+ $finalHash . self::CHUNK_HASH_SEPARATOR .
+ $this->generateHashFromRawData($lastChunk);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: Adding EOP chunk with size of ' . strlen($chunkData) . ',finalHash=' . $finalHash . ' ...');
+
+ // Add it as regular chunk
+ $this->addChunkData($finalHash, $chunkData);
+ }
+
+ /**
+ * Splits the given encoded data into smaller chunks, the size of the final
+ * and the SEPARATOR is being subtracted from chunk size to fit it into a
+ * TCP package (512 bytes).
+ *
+ * @param $rawData Raw data string
+ * @param $finalHash Final hash from the raw data
+ * @return void
+ */
+ private function splitEncodedDataIntoChunks ($rawData, $finalHash) {
+ // Make sure final hashes with at least 32 bytes can pass
+ assert(strlen($finalHash) >= 32);
+
+ // Calculate real (data) chunk size
+ $dataChunkSize = $this->getDataChunkSizeFromHash($finalHash);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: dataChunkSize=' . $dataChunkSize);
+
+ // Init variables
+ $chunkHash = '';
+ $chunkData = '';
+
+ // Now split it up
+ for ($idx = 0; $idx < strlen($rawData); $idx += $dataChunkSize) {
+ // Get the next chunk
+ $chunkData = substr($rawData, $idx, $dataChunkSize);
+
+ // Add the chunk to the propper array and do all the stuff there
+ $this->addChunkData($finalHash, $chunkData);
+ } // END - for
+
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).');
+
+ // Add end-of-package chunk
+ $this->appendEndOfPackageChunk($chunkData, $finalHash);
+ }
+
+ /**
+ * Adds the given chunk (raw data) to the proper array and hashes it for
+ * later verfication.
+ *
+ * @param $finalHash Final hash for faster processing
+ * @param $chunkData Raw chunk data
+ * @param $prepend Whether append (default) or prepend the chunk
+ * @return void
+ */
+ private function addChunkData ($finalHash, $chunkData, $prepend = FALSE) {
+ // Hash it
+ $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', FALSE);
+
+ // Prepend the hash to the chunk
+ $rawData = (
+ $rawDataHash . self::CHUNK_DATA_HASH_SEPARATOR .
+ $this->getNextHexSerialNumber($finalHash) . self::CHUNK_DATA_HASH_SEPARATOR .
+ $chunkData . self::CHUNK_SEPARATOR
+ );
+
+ // Make sure the chunk is not larger than a TCP package can hold
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: assert: ' . strlen($rawData) . '/' . NetworkPackage::TCP_PACKAGE_SIZE . ' ...');
+ // @TODO This assert broke packages where the hash chunk was very large: assert(strlen($rawData) <= NetworkPackage::TCP_PACKAGE_SIZE);
+
+ // Add it to the array
+ if ($prepend === TRUE) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: Prepending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
+ array_unshift($this->chunkHashes[$finalHash], $rawDataHash);
+ array_unshift($this->chunks[$finalHash] , $rawData);
+ } else {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: Appending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
+
+ // Is the array there?
+ if (!isset($this->chunks[$finalHash])) {
+ // Then initialize it
+ $this->chunks[$finalHash] = array();
+ $this->chunkHashes[$finalHash] = array();
+ } // END - if
+
+ // Add both
+ array_push($this->chunks[$finalHash] , $rawData);
+ array_push($this->chunkHashes[$finalHash], $rawDataHash);
+ }
+ }
+
+ /**
+ * Prepends a chunk (or more) with all hashes from all chunks + final chunk.
+ *
+ * @param $finalHash Final hash from the raw data
+ * @return void
+ */
+ private function prependHashChunk ($finalHash) {
+ // "Implode" the whole array of hashes into one string
+ $rawData = self::HASH_CHUNK_IDENTIFIER . implode(self::CHUNK_HASH_SEPARATOR, $this->chunkHashes[$finalHash]);
+
+ // Prepend chunk
+ $this->addChunkData($finalHash, $rawData, TRUE);
+ }
+
+ /**
+ * "Getter" for the next hexadecimal-encoded serial number
+ *
+ * @param $finalHash Final hash
+ * @return $encodedSerialNumber The next hexadecimal-encoded serial number
+ */
+ public function getNextHexSerialNumber ($finalHash) {
+ // Assert on maximum serial number length
+ assert(isset($this->serialNumber[$finalHash]));
+ assert($this->serialNumber[$finalHash] <= $this->maxSerialNumber);
+
+ // Encode the current serial number
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: serialNumber[' . $finalHash . ']=' . $this->serialNumber[$finalHash]);
+ $encodedSerialNumber = $this->dec2Hex($this->serialNumber[$finalHash], self::MAX_SERIAL_LENGTH);
+
+ // Count one up
+ $this->serialNumber[$finalHash]++;
+
+ // Return the encoded serial number
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: encodedSerialNumber=' . $encodedSerialNumber);
+ return $encodedSerialNumber;
+ }
+
+ /**
+ * This method does "implode" the given package data array into one long
+ * string, splits it into small chunks, adds a serial number and checksum
+ * 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 Raw package data array
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @return $finalHash Final hash for faster processing
+ * @todo $helperInstance is unused
+ */
+ public function fragmentPackageArray (array $packageData, ConnectionHelper $helperInstance) {
+ // Is this package already fragmented?
+ if (!$this->isPackageProcessed($packageData)) {
+ // First we need to "implode" the array
+ $rawData = implode(NetworkPackage::PACKAGE_DATA_SEPARATOR, $packageData);
+
+ // Generate the final hash from the raw data (not encoded!)
+ $finalHash = $this->generateHashFromRawData($rawData);
+
+ // Remember it
+ $this->processedPackages[$this->getProcessedPackagesIndex($packageData)] = $finalHash;
+
+ // Init pointer and reset serial number
+ $this->initPointer($finalHash);
+ $this->resetSerialNumber($finalHash);
+
+ // Split the encoded data into smaller chunks
+ $this->splitEncodedDataIntoChunks($rawData, $finalHash);
+
+ // Prepend a chunk with all hashes together
+ $this->prependHashChunk($finalHash);
+
+ // Mark the package as fragmented
+ $this->markPackageDataProcessed($packageData);
+ } else {
+ // Get the final hash from the package data
+ $finalHash = $this->getFinalHashFromPackageData($packageData);
+ }
+
+ // Return final hash
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
+ return $finalHash;
+ }
+
+ /**
+ * This method gets the next chunk from the internal FIFO which should be
+ * sent to the given recipient. It will return an associative array where
+ * the key is the chunk hash and value the raw chunk data.
+ *
+ * @param $finalHash Final hash for faster lookup
+ * @return $rawDataChunk Raw package data chunk
+ * @throws AssertionException If $finalHash was not 'TRUE'
+ */
+ public function getNextRawDataChunk ($finalHash) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
+
+ try {
+ // Get current chunk index
+ $current = $this->getCurrentChunkPointer($finalHash);
+ } catch (AssertionException $e) {
+ // This may happen when the final hash is TRUE
+ if ($finalHash === TRUE) {
+ // Set current to null
+ $current = NULL;
+ } else {
+ // Throw the exception
+ throw $e;
+ }
+ }
+
+ // If there is no entry left, return an empty array
+ if ((!isset($this->chunkHashes[$finalHash][$current])) || (!isset($this->chunks[$finalHash][$current]))) {
+ // No more entries found
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__. ': finalHash=' . $finalHash . ',current=' . $current . ' - No more entries found!');
+ return array();
+ } // END - if
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__. ': finalHash=' . $finalHash . ',current=' . $current . ',chunkHashes()=' . count($this->chunkHashes[$finalHash]) .' - Entry choosen ...');
+
+ // Generate the array
+ $rawDataChunk = array(
+ $this->chunkHashes[$finalHash][$current] => $this->chunks[$finalHash][$current]
+ );
+
+ // Count one index up
+ $this->nextChunkPointer($finalHash);
+
+ // Return the chunk array
+ return $rawDataChunk;
+ }
+
+ /**
+ * Resets the serial number to zero for given final hash
+ *
+ * @param $finalHash Final hash to reset counter for
+ * @return void
+ */
+ public function resetSerialNumber ($finalHash) {
+ // Final hash must be set
+ assert((is_string($finalHash)) && (!empty($finalHash)));
+
+ // Reset/set serial number
+ $this->serialNumber[$finalHash] = 0;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ *
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Pool extends BasePool implements Poolable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listenerInstance A Listenable instance
+ * @return $poolInstance An instance a Poolable class
+ */
+ public final static function create???Pool (Listenable $listenerInstance) {
+ // Get new instance
+ $poolInstance = new ???Pool();
+
+ // Set the application instance
+ $poolInstance->setListenerInstance($listenerInstance);
+
+ // Return the prepared instance
+ return $poolInstance;
+ }
+
+ /**
+ * Adds a listener instance to this pool
+ *
+ * @param $poolInstance An instance of a Listenable class
+ * @return void
+ * @todo 0% done
+ */
+ public function addListener (Listenable $poolInstance) {
+ $this->partialStub('Need to implement this method. listenerInstance=' . $poolInstance->__toString());
+ }
+}
+
+//
+?>
--- /dev/null
+<?php
+/**
+ * A general pool class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BasePool extends BaseHubSystem implements Visitable {
+ /**
+ * Socket array elements
+ */
+ const SOCKET_ARRAY_RESOURCE = 'resource';
+ const SOCKET_ARRAY_CONN_TYPE = 'connection_type';
+
+ /**
+ * A list of pool entries
+ */
+ private $poolEntriesInstance = NULL;
+
+ /**
+ * An array with all valid connection types
+ */
+ private $connectionTypes = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Init the pool entries
+ $this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class');
+
+ // Init array of connection types
+ $this->connectionTypes = array(
+ BaseConnectionHelper::CONNECTION_TYPE_INCOMING,
+ BaseConnectionHelper::CONNECTION_TYPE_OUTGOING,
+ BaseConnectionHelper::CONNECTION_TYPE_SERVER
+ );
+ }
+
+ /**
+ * Getter for pool entries instance
+ *
+ * @return $poolEntriesInstance An instance for pool entries (list)
+ */
+ public final function getPoolEntriesInstance () {
+ return $this->poolEntriesInstance;
+ }
+
+ /**
+ * Adds an instance to a pool segment
+ *
+ * @param $group Name of the pool group
+ * @param $poolSegment Name of the pool segment
+ * @param $visitableInstance An instance of a class that should bed added to the pool
+ * @return void
+ */
+ protected final function addInstance ($group, $poolName, Visitable $visitableInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: group=' . $group . ',poolName=' . $poolName . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!');
+
+ // Make sure the group is not 'invalid'
+ assert($group != 'invalid');
+
+ // Is the pool group there?
+ if (!$this->getPoolEntriesInstance()->isGroupSet($group)) {
+ // Create the missing pool group
+ $this->getPoolEntriesInstance()->addGroup($group);
+ } // END - if
+
+ // Add it to given pool group
+ $this->getPoolEntriesInstance()->addInstance($group, $poolName, $visitableInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Adds an entry to the pool
+ *
+ * @param $poolEntry The new pool entry that should be added
+ * @return void
+ */
+ protected final function addPoolEntry ($poolEntry) {
+ $this->getPoolEntriesInstance()->addEntry('pool', $poolEntry);
+ }
+
+ /**
+ * Accepts the visitor to process the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - CALLED!');
+
+ // Visit this pool
+ $visitorInstance->visitPool($this);
+
+ // Do we have a registry instance for this visitor's iterator?
+ if (Registry::getRegistry()->instanceExists($visitorInstance->getVisitorMode() . '_pool_iterator')) {
+ // Get the instance from registry
+ $iteratorInstance = Registry::getRegistry()->getInstance($visitorInstance->getVisitorMode() . '_pool_iterator');
+ } else {
+ // Get a new iterator instance
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance()));
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance($visitorInstance->getVisitorMode() . '_pool_iterator', $iteratorInstance);
+ }
+
+ // Reset the counter
+ $iteratorInstance->rewind();
+
+ // Visit all registered entries
+ while ($iteratorInstance->valid()) {
+ // Get current entry
+ $poolEntry = $iteratorInstance->current();
+
+ // Is this entry visitable?
+ if ($poolEntry instanceof Visitable) {
+ // Visit this entry as well
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-POOL[' . __METHOD__ . ':' . __LINE__ . ']: Going to visit pooled object ' . $poolEntry->__toString() . ' with visitor ' . $visitorInstance->__toString() . ' ...');
+ $poolEntry->accept($visitorInstance);
+ } else {
+ // Cannot visit this entry
+ $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . ', reason: not implementing Visitable.');
+ }
+
+ // Advance to next entry
+ $iteratorInstance->next();
+ } // END - while
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - EXIT!');
+ }
+
+ /**
+ * Gets the array from specified list
+ *
+ * @param $list The list identifier we should return
+ * @return $array The requested array
+ */
+ protected final function getArrayFromList ($list) {
+ // Get the array
+ $array = $this->getPoolEntriesInstance()->getArrayFromList($list);
+
+ // Return it
+ return $array;
+ }
+
+ /**
+ * Checks whether the given connection type is valid
+ *
+ * @param $connectionType Type of connection, can be 'incoming', 'outgoing' or 'server'
+ * @return $isValid Whether the provided connection type is valid
+ */
+ protected function isValidConnectionType ($connectionType) {
+ // Is it valid?
+ $isValid = in_array($connectionType, $this->connectionTypes, TRUE);
+
+ // Return result
+ return $isValid;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A default listener pool
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DefaultListenerPool extends BasePool implements PoolableListener {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance A NodeHelper instance
+ * @return $listenerInstance An instance a prepared listener class
+ */
+ public static final function createDefaultListenerPool (NodeHelper $nodeInstance) {
+ // Get new instance
+ $listenerInstance = new DefaultListenerPool();
+
+ // Return the prepared instance
+ return $listenerInstance;
+ }
+
+ /**
+ * Adds a listener instance to this pool
+ *
+ * @param $listenerInstance An instance of a Listenable class
+ * @return void
+ */
+ public function addListener (Listenable $listenerInstance) {
+ // Add this listener instance to the instance list
+ parent::addInstance($listenerInstance->getProtocolName(), 'listener', $listenerInstance);
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput(
+ 'POOL[' . __METHOD__ . ':' . __LINE__ . ']: Listener ' . $listenerInstance->__toString() .
+ ' listening to ' . $listenerInstance->getListenAddress() . ':' .
+ $listenerInstance->getListenPort() . ' added to listener pool.'
+ );
+ }
+
+ /**
+ * Run the shutdown seqeuence by a Visitor Pattern
+ *
+ * @return void
+ */
+ public function doShutdown () {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down listener pool - CALLED!');
+
+ // Get a new visitor
+ $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_listener_pool_visitor_class');
+
+ // Start visiting
+ $this->accept($visitorInstance);
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down listener pool - EXIT!');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A default peer pool class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DefaultPeerPool extends BasePool implements PoolablePeer {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listenerInstance A Listenable instance
+ * @return $poolInstance An instance a Poolable class
+ */
+ public static final function createDefaultPeerPool (Listenable $listenerInstance) {
+ // Get new instance
+ $poolInstance = new DefaultPeerPool();
+
+ // Set the application instance
+ $poolInstance->setListenerInstance($listenerInstance);
+
+ // Return the prepared instance
+ return $poolInstance;
+ }
+
+ /**
+ * Validates given socket
+ *
+ * @param $socketResource A valid socket resource
+ * @return void
+ * @throws InvalidSocketException If the given socket has an error
+ */
+ private function validateSocket ($socketResource) {
+ // Is it a valid resource?
+ if (!is_resource($socketResource)) {
+ // Throw an exception
+ throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ // Get error code
+ $errorCode = socket_last_error($socketResource);
+
+ // Is it without any errors?
+ if ($errorCode > 0) {
+ // Handle the socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
+ /*
+ // Get error message
+ $errorMessage = socket_strerror($errorCode);
+
+ // Shutdown this socket
+ $this->getListenerInstance()->shutdownSocket($socketResource);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, $socketResource, $errorCode, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+ }
+
+ /**
+ * Adds a socket resource to the peer pool
+ *
+ * @param $socketResource A valid (must be!) socket resource
+ * @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server'
+ * @return void
+ * @throws InvalidSocketException If the given resource is invalid or errorous
+ * @throws InvalidConnectionTypeException If the provided connection type is not valid
+ */
+ public function addPeer ($socketResource, $connectionType) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DEFAULT-PEER-POOL[' . __METHOD__ . ':' . __LINE__ . ']: socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',connectionType=' . $connectionType . ' - CALLED!');
+
+ // Validate the socket
+ $this->validateSocket($socketResource);
+
+ // Is the connection type valid?
+ if (!$this->isValidConnectionType($connectionType)) {
+ // Is not a valid connection type!
+ throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
+ } // END - if
+
+ // Default is this peer's IP
+ $peerName = '0.0.0.0';
+
+ // The socket resource should not match server socket
+ if ($socketResource != $this->getListenerInstance()->getSocketResource()) {
+ // Try to determine the peer's IP number
+ if (!socket_getpeername($socketResource, $peerName)) {
+ // Handle the socket error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
+ /*
+ // Get last error
+ $lastError = socket_last_error($socketResource);
+
+ // Doesn't work!
+ throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+ */
+ } // END - if
+ } else {
+ // Server sockets won't work with socket_getpeername()
+ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Socket resource is server socket (' . $socketResource . '). This is not a bug.');
+ }
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Adding peer ' . $peerName . ',socketResource=' . $socketResource . ',type=' . $connectionType);
+
+ // Construct the array
+ $socketArray = array(
+ self::SOCKET_ARRAY_RESOURCE => $socketResource,
+ self::SOCKET_ARRAY_CONN_TYPE => $connectionType
+ );
+
+ // Add it finally to the pool
+ $this->addPoolEntry($socketArray);
+ }
+
+ /**
+ * Getter for array of all socket resources
+ *
+ * @return $sockets An array with all sockets
+ */
+ public final function getAllSockets () {
+ // Get the list
+ $sockets = $this->getArrayFromList('pool');
+
+ // Return it
+ return $sockets;
+ }
+
+ /**
+ * Getter for array of all socket arrays
+ *
+ * @return $sockets An array with all socket arrays
+ */
+ public final function getAllSingleSockets () {
+ // Get the array list
+ $socketArrays = $this->getArrayFromList('pool');
+
+ // Init socket array
+ $sockets = array();
+
+ // "Walk" through all socket arrays
+ foreach ($socketArrays as $socketArray) {
+ // Add the socket
+ array_push($sockets, $socketArray[self::SOCKET_ARRAY_RESOURCE]);
+ } // END - foreach
+
+ // Return it
+ return $sockets;
+ }
+
+ /**
+ * "Getter" for all sockets of specified type
+ *
+ * @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server'
+ * @return $sockets An array with sockets of given type
+ * @throws InvalidConnectionTypeException If the provided connection type is not valid
+ */
+ public function getSocketsByConnectionType ($connectionType) {
+ // Is the connection type valid?
+ if (!$this->isValidConnectionType($connectionType)) {
+ // Is not a valid connection type!
+ throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
+ } // END - if
+
+ // Get the array list
+ $socketArrays = $this->getArrayFromList('pool');
+
+ // Init socket array
+ $sockets = array();
+
+ // "Walk" through all socket arrays
+ foreach ($socketArrays as $socketArray) {
+ // Does it match?
+ if ($socketArray[self::SOCKET_ARRAY_CONN_TYPE] === $connectionType) {
+ // Add the socket
+ array_push($sockets, $socketArray[self::SOCKET_ARRAY_RESOURCE]);
+ } // END - if
+ } // END - foreach
+
+ // Return it
+ return $sockets;
+ }
+
+ /**
+ * "Getter" for a valid socket resource from given packae data.
+ *
+ * @param $packageData Raw package data
+ * @param $connectionType Type of connection, can be 'incoming', 'outgoing', 'server' or default
+ * @return $socketResource Socket resource
+ * @throws InvalidConnectionTypeException If the provided connection type is not valid
+ */
+ public function getSocketFromPackageData (array $packageData, $connectionType = NULL) {
+ // Default is no socket
+ $socketResource = FALSE;
+
+ // Resolve recipient (UNL) into a handler instance
+ $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
+
+ // Get UNL data
+ $unlData = $handlerInstance->getUniversalNodeLocatorDataArray();
+
+ // Make sure it is a valid Universal Node Locator array (3 elements)
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[' . UniversalNodeLocator::UNL_PART_ADDRESS . ']=' . $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] . ',unlData[' . UniversalNodeLocator::UNL_PART_PORT . ']=' . $unlData[UniversalNodeLocator::UNL_PART_PORT] . ' ...');
+
+ // Default is all sockets
+ $sockets = $this->getAllSockets();
+
+ // Is connection type set?
+ if ((is_string($connectionType)) && ($this->isValidConnectionType($connectionType))) {
+ // Then get a list of this type
+ $sockets = $this->getSocketsByConnectionType($connectionType);
+ } elseif (is_string($connectionType)) {
+ // Is not a valid connection type!
+ throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
+ }
+
+ // Get all sockets and check them, skip the server socket
+ foreach ($sockets as $socketArray) {
+ // Is this a server socket?
+ if ($socketArray[self::SOCKET_ARRAY_RESOURCE] === $this->getListenerInstance()->getSocketResource()) {
+ // Skip 'server' sockets (local socket)
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Skipping server socket ' . $socketArray[self::SOCKET_ARRAY_RESOURCE] . ' ...');
+ continue;
+ } // END - if
+
+ // Try to get the "peer"'s name
+ if (!socket_getpeername($socketArray[self::SOCKET_ARRAY_RESOURCE], $peerIp)) {
+ // Handle the socket error with given package data
+ $this->handleSocketError(__METHOD__, __LINE__, $socketArray[self::SOCKET_ARRAY_RESOURCE], explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+ } // END - if
+
+ // Get
+ // If the "peer" IP and recipient is same, use it
+ if ($peerIp == $unlData[UniversalNodeLocator::UNL_PART_ADDRESS]) {
+ // IPs match, so take the socket and quit this loop
+ $socketResource = $socketArray[self::SOCKET_ARRAY_RESOURCE];
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: peerIp=' . $peerIp . ' matches with recipient IP address. Taking socket=' . $socketArray[self::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[self::SOCKET_ARRAY_CONN_TYPE]);
+ break;
+ } // END - if
+ } // END - foreach
+
+ // Return the determined socket resource
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: socketResource[' . gettype($socketResource) . ']=' . $socketResource);
+ return $socketResource;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? producer class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Producer extends BaseProducer implements Producer, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $producerInstance An instance of a Producer class
+ */
+ public final static function create???Producer () {
+ // Get new instance
+ $producerInstance = new ???Producer();
+
+ // Return the prepared instance
+ return $producerInstance;
+ }
+
+ /**
+ * Initializes the producer
+ *
+ * @return void
+ */
+ protected function initProducer () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Producer class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
+ */
+abstract class BaseProducer extends BaseFrameworkSystem {
+ /**
+ * Outgoing work-queue
+ */
+ private $outgoingQueueInstance = NULL;
+
+ /**
+ * Incoming raw data/items queue
+ */
+ private $incomingQueueInstance = NULL;
+
+ /**
+ * Stacker name for incoming work
+ */
+ const STACKER_NAME_IN_QUEUE = 'incoming_queue';
+
+ /**
+ * Stacker name for outgoing work
+ */
+ const STACKER_NAME_OUT_QUEUE = 'outgoing_queue';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Initialize all producers
+ $this->initProducer();
+
+ // Get miner instance
+ $minerInstance = Registry::getRegistry()->getInstance('miner');
+
+ // Change state to next state
+ $minerInstance->blockProducerHasInitialized($this);
+
+ // Initialize work queue (out-going, produced items)
+ $this->initWorkQueue();
+ }
+
+ /**
+ * Getter for outgoing work queue
+ *
+ * @param $outgoingQueueInstance The outgoing work queue instance
+ */
+ protected final function getOutgoingQueueInstance () {
+ return $this->outgoingQueueInstance;
+ }
+
+ /**
+ * Setter for outgoing work queue
+ *
+ * @param $outgoingQueueInstance The outgoing work queue instance
+ * @return void
+ */
+ private final function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) {
+ $this->outgoingQueueInstance = $outgoingQueueInstance;
+ }
+
+ /**
+ * Getter for incoming raw data/items queue
+ *
+ * @param $incomingQueueInstance The incoming raw data/items queue instance
+ */
+ protected final function getIncomingQueueInstance () {
+ return $this->incomingQueueInstance;
+ }
+
+ /**
+ * Setter for incoming raw data/items queue
+ *
+ * @param $incomingQueueInstance The incoming raw data/items queue instance
+ * @return void
+ */
+ private final function setIncomingQueueInstance (Stackable $incomingQueueInstance) {
+ $this->incomingQueueInstance = $incomingQueueInstance;
+ }
+
+ /**
+ * Initializes this producer, this method must be overwritten.
+ *
+ * @return void
+ */
+ abstract protected function initProducer();
+
+ /**
+ * Initializes the work queue which is being used for outgoing, produced
+ * items.
+ *
+ * @return void
+ */
+ protected function initWorkQueue () {
+ // Get an instance and set it in this producer
+ $this->setOutgoingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_outgoing_queue'));
+
+ // Init the queue
+ $this->initOutgoingQueue();
+
+ // Get an instance and set it in this producer
+ $this->setIncomingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_incoming_queue'));
+
+ // Init the queue
+ $this->initIncomingQueue();
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: All queues have been initialized.');
+ }
+
+ /**
+ * Inits the out-going queue stack
+ *
+ * @return void
+ */
+ protected function initOutgoingQueue () {
+ $this->getOutgoingQueueInstance()->initStack(self::STACKER_NAME_OUT_QUEUE, TRUE);
+ }
+
+ /**
+ * Adds an entry to the out-going work queue
+ *
+ * @param $value The value to be added to the out-going work queue
+ * @return void
+ */
+ protected function addValueToOutgoingQueue ($value) {
+ $this->getOutgoingQueueInstance()->pushNamed(self::STACKER_NAME_OUT_QUEUE, $value);
+ }
+
+ /**
+ * Checks whether a configurable out-going queue limit has been reached
+ *
+ * @param $configEntry Configuration entry where the limit is stored
+ * @return $isReached Whether the limit is reached
+ */
+ protected function isOutgoingQueueLimitReached ($configEntry) {
+ return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getOutgoingQueueInstance()->getStackCount(self::STACKER_NAME_OUT_QUEUE));
+ }
+
+ /**
+ * Inits the incoming queue stack
+ *
+ * @return void
+ */
+ protected function initIncomingQueue () {
+ $this->getIncomingQueueInstance()->initStack(self::STACKER_NAME_IN_QUEUE, TRUE);
+ }
+
+ /**
+ * Adds an entry to the incoming work queue
+ *
+ * @param $value The value to be added to the incoming work queue
+ * @return void
+ */
+ protected function addValueToIncomingQueue ($value) {
+ $this->getIncomingQueueInstance()->pushNamed(self::STACKER_NAME_IN_QUEUE, $value);
+ }
+
+ /**
+ * Checks whether a configurable incoming queue limit has been reached
+ *
+ * @param $configEntry Configuration entry where the limit is stored
+ * @return $isReached Whether the limit is reached
+ */
+ protected function isIncomingQueueLimitReached($configEntry) {
+ return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getIncomingQueueInstance()->getStackCount(self::STACKER_NAME_IN_QUEUE));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A general KeyProducer class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
+ */
+abstract class BaseKeyProducer extends BaseProducer {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Init key producer
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general UnitProducer class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
+ */
+abstract class BaseUnitProducer extends BaseProducer {
+ /**
+ * Work/test unit status
+ */
+ const UNIT_STATUS_AVAILABLE = 'available'; // Available for crunching
+ const UNIT_STATUS_PENDING = 'pending'; // Is being crunched at the moment
+ const UNIT_STATUS_DONE = 'done'; // Is already crunched/finished
+
+ /**
+ * Work or test unit?
+ */
+ const UNIT_TYPE_TEST_UNIT = 'test_unit';
+ const UNIT_TYPE_TEST_WORK = 'work_unit';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A CruncherKey producer class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherKeyProducer extends BaseKeyProducer implements KeyProducer, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $producerInstance An instance of a Producer class
+ */
+ public final static function createCruncherKeyProducer () {
+ // Get new instance
+ $producerInstance = new CruncherKeyProducer();
+
+ // Get a helper instance, we now only need this for the key iterator
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('crypto_random_message_helper_class', array('test'));
+
+ // Next get an iterator, again the helper will do that for us
+ $iteratorInstance = $helperInstance->getKeyIterator();
+
+ // Set it in the producer
+ $producerInstance->setIteratorInstance($iteratorInstance);
+
+ // Return the prepared instance
+ return $producerInstance;
+ }
+
+ /**
+ * Initializes the producer. This method satisfies the abstract BaseProducer
+ * class.
+ *
+ * @return void
+ * @todo Find something for init phase of this key producer
+ */
+ protected function initProducer () {
+ }
+
+ /**
+ * Initializes the executor, whatever it does.
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function initExecutor (Stateable $stateInstance) {
+ $this->partialStub('Maybe implement this method?');
+ }
+
+ /**
+ * Produces some keys and pushes them onto the queue
+ *
+ * @param $stateInstance An instance of a Stateable instance
+ * @return void
+ * @todo ~30% done
+ */
+ public function produceKeys (Stateable $stateInstance) {
+ // Is this cruncher virgin?
+ if (!$stateInstance->isCruncherStateVirgin()) {
+ // This cruncher is not virgin, so skip it
+ self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: The cruncher is not virgin. stateInstance=' . $stateInstance->__toString() . '');
+ return;
+ } elseif (!$this->getIteratorInstance()->valid()) {
+ // This producer's iterator has finished its assignment
+ self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: Finished creating keys. iteratorInstance=' . $this->getIteratorInstance()->__toString() . '');
+ return;
+ }
+
+ /*
+ * Now we need to create an iterator, just as for the work units,
+ * to create new keys from the encrypted message. The iterator will
+ * not iterate over an object nor a collection. It will instead
+ * encapsulate the "key production" into a class and not in a simple
+ * for() loop. These keys then needs to be bundled into test units
+ * and stored to database for later re-usage.
+ */
+
+ /*
+ * Get current key (which is not the key of the iterator) This is always
+ * an ASCII string.
+ */
+ $currentKey = $this->getIteratorInstance()->current();
+
+ // Add it to the out-going work queue
+ $this->addValueToOutgoingQueue($currentKey);
+
+ // Is the per-work unit limit reached?
+ if ($this->isOutgoingQueueLimitReached('cruncher_per_unit_key_limit')) {
+ // @TODO Send the produced key bundle to the unit producer's input queue
+ self::createDebugInstance(__CLASS__)->debugOutput('currentKey(b64)="' . base64_encode($currentKey) . '" needs to be processed.');
+
+ // At last re-init the stack
+ $this->initOutgoingQueue();
+ } // END - if
+
+ // Continue with next one
+ $this->getIteratorInstance()->next();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A CruncherTestUnit producer class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $producerInstance An instance of a Producer class
+ */
+ public final static function createCruncherTestUnitProducer () {
+ // Get new instance
+ $producerInstance = new CruncherTestUnitProducer();
+
+ // Test units have a helper class that wraps the source
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('crypto_random_message_helper_class', array('test'));
+
+ // So set it in the producer
+ $producerInstance->setHelperInstance($helperInstance);
+
+ // Return the prepared instance
+ return $producerInstance;
+ }
+
+ /**
+ * Initializes the producer. This method satisfies the abstract BaseProducer
+ * class.
+ *
+ * @return void
+ */
+ protected function initProducer () {
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('cruncher_test_unit_producer_template_class');
+
+ // Load the template
+ $templateInstance->loadXmlTemplate();
+
+ // Render the XML content
+ $templateInstance->renderXmlContent();
+
+ // And set it in this cruncher
+ $this->setTemplateInstance($templateInstance);
+ }
+
+ /**
+ * Prepares the produces of some test units and pushes them onto the queue
+ *
+ * @param $stateInstance An instance of a Stateable instance
+ * @return void
+ * @todo ~60% done
+ */
+ public function initUnitProduction (Stateable $stateInstance) {
+ // First get a database wrapper because we want to permanently store test units
+ $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('cruncher_unit_db_wrapper_class');
+
+ // Do we have some entries?
+ if ($wrapperInstance->isTestUnitProduced()) {
+ // Entries found
+ // @TODO Unfinished work here
+ $this->debugInstance();
+
+ // The state must be changed because ...
+ $stateInstance->someFooStateChange();
+ } else {
+ // Get an encrypted, random message from our source
+ $encryptedMessage = $this->getHelperInstance()->generateRandomMessage();
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: An encrypted, random message has been generated. Generating keys ...');
+
+ // Set the encrypted message in the template instance
+ $this->getTemplateInstance()->assignVariable('encrypted_message', $encryptedMessage);
+
+ // The state must be changed because we have a new message
+ $stateInstance->encryptedMessageGenerated();
+ }
+ }
+
+ /**
+ * Initializes the executor, whatever it does.
+ *
+ * @return void
+ * @todo Maybe unfinished
+ */
+ public function initExecutor (Stateable $stateInstance) {
+ $this->partialStub('Maybe implement this method?');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A MinerRealGenesisBlock producer class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 MinerRealGenesisBlockProducer extends BaseBlockProducer implements BlockProducer, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $producerInstance An instance of a Producer class
+ */
+ public final static function createMinerRealGenesisBlockProducer () {
+ // Get new instance
+ $producerInstance = new MinerRealGenesisBlockProducer();
+
+ // Get a (minable) hash block instance
+ $minableInstance = ObjectFactory::createObjectByConfiguredName('miner_real_hash_block_class');
+
+ // Set it here
+ $producerInstance->setMinableInstance($minableInstance);
+
+ // Return the prepared instance
+ return $producerInstance;
+ }
+
+ /**
+ * Initializes the producer. This method satisfies the abstract BaseProducer
+ * class.
+ *
+ * @return void
+ * @todo 0% done
+ */
+ protected function initProducer () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Initializes the executor, whatever it does.
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function initExecutor (Stateable $stateInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Prepares the produces of some test units and pushes them onto the queue
+ *
+ * @param $stateInstance An instance of a Stateable instance
+ * @return void
+ * @todo ~5% done
+ */
+ public function prepareBlockProduction (Stateable $stateInstance) {
+ // The state must be 'booting'
+ $stateInstance->validateMinerStateIsBooting();
+
+ /*
+ * Now that the miner is booting a genesis block for real mining can be
+ * created.
+ */
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A MinerTestGenesisBlock producer class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 MinerTestGenesisBlockProducer extends BaseBlockProducer implements BlockProducer, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $producerInstance An instance of a Producer class
+ */
+ public final static function createMinerTestGenesisBlockProducer () {
+ // Get new instance
+ $producerInstance = new MinerTestGenesisBlockProducer();
+
+ // Get a (minable) hash block instance
+ $minableInstance = ObjectFactory::createObjectByConfiguredName('miner_test_hash_block_class');
+
+ // Set it here
+ $producerInstance->setMinableInstance($minableInstance);
+
+ // Return the prepared instance
+ return $producerInstance;
+ }
+
+ /**
+ * Initializes the producer. This method satisfies the abstract BaseProducer
+ * class.
+ *
+ * @return void
+ * @todo 0% done
+ */
+ protected function initProducer () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Initializes the executor, whatever it does.
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function initExecutor (Stateable $stateInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Prepares the produces of some test units and pushes them onto the queue
+ *
+ * @param $stateInstance An instance of a Stateable instance
+ * @return void
+ * @todo ~5% done
+ */
+ public function prepareBlockProduction (Stateable $stateInstance) {
+ // The state must be 'booting'
+ $stateInstance->validateMinerStateIsBooting();
+
+ /*
+ * Now that the miner is booting a "genesis" block for testing purposes
+ * can be created. The real "genesis" block will be created differently
+ * to this.
+ */
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general BlockProducer class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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/>.
+ */
+abstract class BaseBlockProducer extends BaseProducer {
+ /**
+ * Block status
+ */
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// @DEPRECATED
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? recipient
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Recipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function create???Recipient () {
+ // Get new instance
+ $recipientInstance = new ???Recipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * 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
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @throws FrameworkException Could throw different exceptions back depending on implementation
+ * @todo 0% done
+ */
+ public function resolveRecipient ($recipient, Listable $listInstance) {
+ // Make sure the recipient is valid
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('!!!-RECIPIENT: recipient=' . $recipient);
+ assert($recipient == '|||');
+ $this->partialStub('Please implement this method. recipient=' . $recipient);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Recipient class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseRecipient extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A DHT recipient
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtRecipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function createDhtRecipient () {
+ // Get new instance
+ $recipientInstance = new DhtRecipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * Tries to resolve given recipient into session ids or Universal Node Locator
+ * depending on implementation (hint: Template Method Pattern). This
+ * 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 Valid package data array
+ * @return void
+ * @throws FrameworkException Could throw different exceptions depending on implementation
+ */
+ public function resolveRecipient ($recipient, Listable $listInstance, array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient . ' - CALLED!');
+
+ // Make sure the recipient is valid
+ assert($recipient == NetworkPackage::NETWORK_TARGET_DHT);
+
+ // Get recipient discovery instance
+ $discoverInstance = ObjectFactory::createObjectByConfiguredName('dht_recipient_discovery_class');
+
+ // "Discover" recipients by given package data
+ $recipients = $discoverInstance->resolveRecipientsByPackageData($packageData);
+
+ // Now "walk" through all elements and add them to the list
+ foreach ($recipients as $recipient) {
+ // These array elements must exist for this loop:
+ // @TODO Unfinished
+ die(__METHOD__ . ':recipient=' . print_r($recipient, TRUE));
+ assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]));
+
+ // Put ip and port both together
+ $unl = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS];
+
+ // Add it to the list
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: Calling listInstance->addEntry(' . $unl . ') ...');
+ $listInstance->addEntry('unl', $unl);
+ } // END - foreach
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient . ' - EXIT!');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Direct recipient
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DirectRecipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function createDirectRecipient () {
+ // Get new instance
+ $recipientInstance = new DirectRecipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * 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 Valid package data array
+ * @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, array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient);
+
+ // "Explode" all recipients
+ $recipients = explode(NetworkPackage::PACKAGE_RECIPIENT_SEPARATOR, $recipient);
+
+ // Is maximum reached?
+ assert(count($recipients) <= $this->getConfigInstance()->getConfigEntry('package_recipient_max_count'));
+
+ // Try it on all
+ foreach ($recipients as $recipient) {
+ // Try to sole a single recipient
+ $unlData = HubTools::resolveSessionId($recipient);
+
+ // Add it as recipient
+ $listInstance->addEntry('unl', $unlData);
+ } // END - foreach
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Self recipient
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 SelfRecipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function createSelfRecipient () {
+ // Get new instance
+ $recipientInstance = new SelfRecipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * 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 Valid package data array
+ * @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, array $packageData) {
+ // Make sure the recipient is valid
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient);
+ // @TODO Add more checks on data
+ assert($recipient == NetworkPackage::NETWORK_TARGET_SELF);
+
+ // Determine IP or 'external_address' if set
+ $unl = HubTools::determineOwnExternalAddress();
+
+ // Is it not empty?
+ if (!empty($unl)) {
+ // Add it to the list
+ $listInstance->addEntry('unl', $unl);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Upper recipient
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UpperRecipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function createUpperRecipient () {
+ // Get new instance
+ $recipientInstance = new UpperRecipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * 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 Valid package data array
+ * @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, array $packageData) {
+ // Make sure the recipient is valid
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('UPPER-RECIPIENT: recipient=' . $recipient);
+ assert($recipient == NetworkPackage::NETWORK_TARGET_UPPER);
+
+ // Get all bootstrap nodes
+ foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlData) {
+ // Is maximum reached?
+ if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER[' . __METHOD__ . ':' . __LINE__ . ']: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
+
+ // Then stop adding more
+ break;
+ } // END - if
+
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER[' . __METHOD__ . ':' . __LINE__ . ']: Adding node ' . print_r($unlData, TRUE) . ' as recipient.');
+
+ // Add the entry
+ $listInstance->addEntry('unl', $unlData);
+ } // END - foreach
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ObjectType registry
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ObjectTypeRegistry extends BaseRegistry implements Register {
+ /**
+ * Instance of this class
+ */
+ private static $registryInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Singleton method, we really only need one instance of this class.
+ *
+ * @return $registryInstance Instance of this class
+ */
+ public static final function createObjectTypeRegistry () {
+ // Is an instance there?
+ if (is_null(self::$registryInstance)) {
+ // Not yet, so create one
+ self::$registryInstance = new ObjectTypeRegistry();
+ } // END - if
+
+ // Return the instance
+ return self::$registryInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Socket registry
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 SocketRegistry extends BaseRegistry implements Register, RegisterableSocket {
+ // Exception constants
+ const SOCKET_NOT_REGISTERED = 0xd200;
+
+ /**
+ * Instance of this class
+ */
+ private static $registryInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates a singleton instance of this registry class
+ *
+ * @return $registryInstance An instance of this class
+ */
+ public static final function createSocketRegistry () {
+ // Is an instance there?
+ if (is_null(self::$registryInstance)) {
+ // Not yet, so create one
+ self::$registryInstance = new SocketRegistry();
+ } // END - if
+
+ // Return the instance
+ return self::$registryInstance;
+ }
+
+ /**
+ * "Getter" to get a string respresentation for a key for the sub-registry
+ * in this format: class:type:port
+ *
+ * @param $infoInstance An instance of a ShareableInfo class
+ * @return $key A string representation of the socket for the registry
+ */
+ private function getSubRegistryKey (ShareableInfo $infoInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: infoInstance=' . $infoInstance->__toString() . ' - CALLED!');
+
+ // Get address and port
+ $address = $infoInstance->getAddress();
+ $port = $infoInstance->getPort();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: address=' . $address . ',port=' . $port);
+
+ // Get connection type and port number and add both together
+ $key = sprintf('%s:%s:%s:%s',
+ $infoInstance->__toString(),
+ $infoInstance->getProtocolName(),
+ $address,
+ $port
+ );
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ' - EXIT!');
+
+ // Return resulting key
+ return $key;
+ }
+
+ /**
+ * "Getter" to get a string respresentation of the listener
+ *
+ * @param $infoInstance An instance of a ShareableInfo class
+ * @return $key A string representation of the listener for the registry
+ */
+ private function getRegistryKeyFromInfo (ShareableInfo $infoInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',infoInstance=' . $infoInstance->__toString() . ' - CALLED!');
+
+ // Get the key
+ $key = $infoInstance->getProtocolName();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ' - EXIT!');
+
+ // Return resulting key
+ return $key;
+ }
+
+ /**
+ * Checks whether the shared connection info is registered
+ *
+ * @param $infoInstance An instance of a ShareableInfo class
+ * @return $isRegistered Whether the listener is registered
+ */
+ private function isInfoRegistered (ShareableInfo $infoInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ' - CALLED!');
+
+ // Get the key
+ $key = $this->getRegistryKeyFromInfo($infoInstance);
+
+ // Determine it
+ $isRegistered = $this->instanceExists($key);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
+
+ // Return result
+ return $isRegistered;
+ }
+
+ /**
+ * Checks whether given socket resource is registered. If $socketResource is
+ * FALSE only the instance will be checked.
+ *
+ * @param $infoInstance An instance of a ShareableInfo class
+ * @param $socketResource A valid socket resource
+ * @return $isRegistered Whether the given socket resource is registered
+ */
+ public function isSocketRegistered (ShareableInfo $infoInstance, $socketResource) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - CALLED!');
+
+ // Default is not registered
+ $isRegistered = FALSE;
+
+ // First, check for the instance, there can be only once
+ if ($this->isInfoRegistered($infoInstance)) {
+ // That one is found so "get" a registry key from it
+ $key = $this->getRegistryKeyFromInfo($infoInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...');
+
+ // Get the registry
+ $registryInstance = $this->getInstance($key);
+
+ // "Get" a key for the socket
+ $socketKey = $this->getSubRegistryKey($infoInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...');
+
+ // Is it there?
+ if ($registryInstance->instanceExists($socketKey)) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: Found instance for socketKey=' . $socketKey . ':' . $registryInstance->getInstance($socketKey));
+
+ // Get the instance
+ $registeredInstance = $registryInstance->getInstance($socketKey);
+
+ // Is it SocketContainer and same socket?
+ $isRegistered = (($registeredInstance instanceof SocketContainer) && ($registeredInstance->ifSocketResourceMatches($socketResource)));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: Final result: isRegistered(' . $socketResource . ')=' . intval($isRegistered));
+ } // END - if
+ } // END - if
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
+
+ // Return the result
+ return $isRegistered;
+ }
+
+ /**
+ * Registeres given socket for listener or throws an exception if it is already registered
+ *
+ * @param $infoInstance An instance of a ShareableInfo class
+ * @param $socketResource A valid socket resource
+ * @param $packageData Optional raw package data
+ * @throws SocketAlreadyRegisteredException If the given socket is already registered
+ * @return void
+ */
+ public function registerSocket (ShareableInfo $infoInstance, $socketResource, array $packageData = array()) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - CALLED!');
+
+ // Is the socket already registered?
+ if ($this->isSocketRegistered($infoInstance, $socketResource)) {
+ // Throw the exception
+ throw new SocketAlreadyRegisteredException(array($infoInstance, $socketResource), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
+ } // END - if
+
+ // Does the instance exist?
+ if (!$this->isInfoRegistered($infoInstance)) {
+ // No, not found so we create a sub registry (not needed to configure!)
+ $registryInstance = SubRegistry::createSubRegistry();
+
+ // Now we can create the sub-registry for this info
+ $this->addInstance($this->getRegistryKeyFromInfo($infoInstance), $registryInstance);
+ } else {
+ // Get the sub-registry back
+ $registryInstance = $this->getInstance($this->getRegistryKeyFromInfo($infoInstance));
+ }
+
+ // Get a key for sub-registries
+ $socketKey = $this->getSubRegistryKey($infoInstance);
+
+ // Get a socket container
+ $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $infoInstance, $packageData));
+
+ // We have a sub-registry, the socket key and the socket, now we need to put all together
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: socketKey=' . $socketKey . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - adding socket container instance ...');
+ $registryInstance->addInstance($socketKey, $socketInstance);
+ }
+
+ /**
+ * Getter for given listener's socket resource
+ *
+ * @param $listenerInstance An instance of a Listenable class
+ * @return $socketResource A valid socket resource
+ * @throws NoSocketRegisteredException If the requested socket is not registered
+ */
+ public function getRegisteredSocketResource (Listenable $listenerInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ' - CALLED!');
+
+ // The socket must be registered before we can return it
+ if (!$this->isInfoRegistered($listenerInstance)) {
+ // Throw the exception
+ throw new NoSocketRegisteredException ($listenerInstance, self::SOCKET_NOT_REGISTERED);
+ } // END - if
+
+ // Now get the key from the listener
+ $key = $this->getRegistryKeyFromInfo($listenerInstance);
+
+ // And get the registry
+ $registryInstance = $this->getInstance($key);
+
+ // Get a socket key
+ $socketKey = $this->getSubRegistryKey($listenerInstance);
+
+ // And the final socket resource
+ $socketResource = $registryInstance->getInstance($socketKey)->getSocketResource();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!');
+
+ // Return the resource
+ return $socketResource;
+ }
+
+ /**
+ * "Getter" for info instance from given package data
+ *
+ * @param $packageData Raw package data
+ * @return $infoInstance An instance of a ShareableInfo class
+ */
+ public function getInfoInstanceFromPackageData (array $packageData) {
+ // Init info instance
+ $infoInstance = NULL;
+ //* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
+
+ // Get all keys and check them
+ foreach ($this->getInstanceRegistry() as $key => $registryInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',registryInstance=' . $registryInstance->__toString());
+
+ // This is always a SubRegistry instance
+ foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString());
+
+ // Is this a SocketContainer instance and is the address the same?
+ if (($containerInstance instanceof SocketContainer) && ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]))) {
+ // Debug die
+ //* DEBUG-DIE: */ die(__METHOD__ . ': containerInstance=' . print_r($containerInstance, TRUE));
+
+ // Get listener and helper instances
+ $listenerInstance = $containerInstance->getListenerInstance();
+ $helperInstance = $containerInstance->getHelperInstance();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
+
+ // Is a listener or helper set?
+ if ($listenerInstance instanceof Listenable) {
+ // Found a listener, so get the info instance first
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($listenerInstance->getProtocolName(), 'helper');
+
+ // Fill info instance with listener data
+ $infoInstance->fillWithListenerInformation($listenerInstance);
+ } elseif ($helperInstance instanceof ConnectionHelper) {
+ // Found a helper, so get the info instance first
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($helperInstance->getProtocolName(), 'helper');
+
+ // Helper is found
+ $infoInstance->fillWithConnectionHelperInformation($helperInstance);
+ } else {
+ // Not supported state!
+ $this->debugInstance('[' . __METHOD__ . ':' . __LINE__ . ']: Invalid state found, please report this to the developers with full debug infos.' . PHP_EOL);
+ }
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',infoInstance[' . gettype($infoInstance) . ']=' . $infoInstance->__toString() . ' with protocol ' . $infoInstance->getProtocolName() . ' - FOUND!');
+ break;
+ } // END - if
+ } // END - foreach
+
+ // Is no longer NULL set?
+ if (!is_null($infoInstance)) {
+ // Then skip here, too
+ break;
+ } // END - if
+ } // END - foreach
+
+ // Return the info instance
+ return $infoInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A command resolver for local (non-hubbed) web commands
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubConsoleCommandResolver extends BaseCommandResolver implements CommandResolver {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set prefix to "HubConsole"
+ $this->setClassPrefix('hub_console');
+ }
+
+ /**
+ * Creates an instance of a HubConsole command resolver with a given default command
+ *
+ * @param $commandName The default command we shall execute
+ * @param $applicationInstance An instance of a manageable application helper class
+ * @return $resolverInstance The prepared command resolver instance
+ * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidCommandException Thrown if default command is invalid
+ */
+ public static final function createHubConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) {
+ // Create the new instance
+ $resolverInstance = new HubConsoleCommandResolver();
+
+ // Is the variable $commandName set and the command is valid?
+ if (empty($commandName)) {
+ // Then thrown an exception here
+ throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif ($resolverInstance->isCommandValid($commandName) === FALSE) {
+ // Invalid command found
+ throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
+ }
+
+ // Set the application instance
+ $resolverInstance->setApplicationInstance($applicationInstance);
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A command resolver for HTML commands
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2015 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 HubHtmlCommandResolver extends BaseCommandResolver implements CommandResolver {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set prefix to "HubHtml"
+ $this->setClassPrefix('hub_html');
+ }
+
+ /**
+ * Creates an instance of a HubHtml command resolver with a given default command
+ *
+ * @param $commandName The default command we shall execute
+ * @param $applicationInstance An instance of a manageable application helper class
+ * @return $resolverInstance The prepared command resolver instance
+ * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidCommandException Thrown if default command is invalid
+ */
+ public static final function createHubHtmlCommandResolver ($commandName, ManageableApplication $applicationInstance) {
+ // Create the new instance
+ $resolverInstance = new HubHtmlCommandResolver();
+
+ // Is the variable $commandName set and the command is valid?
+ if (empty($commandName)) {
+ // Then thrown an exception here
+ throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif ($resolverInstance->isCommandValid($commandName) === FALSE) {
+ // Invalid command found
+ throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
+ }
+
+ // Set the application instance
+ $resolverInstance->setApplicationInstance($applicationInstance);
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A resolver for resolving controllers locally
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubConsoleControllerResolver extends BaseControllerResolver implements ControllerResolver {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set prefix to "HubConsole"
+ $this->setClassPrefix('hub_console');
+ }
+
+ /**
+ * Creates an instance of a resolver class with a given command
+ *
+ * @param $controllerName The controller we shall resolve
+ * @param $applicationInstance An instance of a manageable application helper class
+ * @return $resolverInstance The prepared controller resolver instance
+ * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidControllerException Thrown if default controller is invalid
+ */
+ public static final function createHubConsoleControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
+ // Create the new instance
+ $resolverInstance = new HubConsoleControllerResolver();
+
+ // Is the variable $controllerName set and the command is valid?
+ if (empty($controllerName)) {
+ // Then thrown an exception here
+ throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) {
+ // Invalid command found
+ throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+ }
+
+ // Set the application instance
+ $resolverInstance->setApplicationInstance($applicationInstance);
+
+ // Set command name
+ $resolverInstance->setControllerName($controllerName);
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+
+ /**
+ * Resolves the default controller of the given command
+ *
+ * @return $controllerInstance A controller instance for the default
+ * command
+ * @throws InvalidControllerInstanceException Thrown if $controllerInstance
+ * is invalid
+ */
+ public function resolveController () {
+ // Init variables
+ $controllerName = '';
+ $controllerInstance = NULL;
+
+ // Get the command name
+ $controllerName = $this->getControllerName();
+
+ // Get the command
+ $controllerInstance = $this->loadController($controllerName);
+
+ // And validate it
+ if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
+ // This command has an invalid instance!
+ throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+ } // END - if
+
+ // Set last controller
+ $this->setResolvedInstance($controllerInstance);
+
+ // Return the maybe resolved instance
+ return $controllerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A resolver for resolving controllers locally
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubHtmlControllerResolver extends BaseControllerResolver implements ControllerResolver {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set prefix to 'Html'
+ $this->setClassPrefix('Html');
+ }
+
+ /**
+ * Creates an instance of a resolver class with a given command
+ *
+ * @param $controllerName The controller we shall resolve
+ * @param $applicationInstance An instance of a manageable application helper class
+ * @return $resolverInstance The prepared controller resolver instance
+ * @throws EmptyVariableException Thrown if default command is not set
+ * @throws InvalidControllerException Thrown if default controller is invalid
+ */
+ public static final function createHubHtmlControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
+ // Create the new instance
+ $resolverInstance = new HubHtmlControllerResolver();
+
+ // Is the variable $controllerName set and the command is valid?
+ if (empty($controllerName)) {
+ // Then thrown an exception here
+ throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) {
+ // Invalid command found
+ throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+ }
+
+ // Set the application instance
+ $resolverInstance->setApplicationInstance($applicationInstance);
+
+ // Set command name
+ $resolverInstance->setControllerName($controllerName);
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+
+ /**
+ * Resolves the default controller of the given command
+ *
+ * @return $controllerInstance A controller instance for the default
+ * command
+ * @throws InvalidControllerInstanceException Thrown if $controllerInstance
+ * is invalid
+ */
+ public function resolveController () {
+ // Init variables
+ $controllerName = '';
+ $controllerInstance = NULL;
+
+ // Get the command name
+ $controllerName = $this->getControllerName();
+
+ // Get the command
+ $controllerInstance = $this->loadController($controllerName);
+
+ // And validate it
+ if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
+ // This command has an invalid instance!
+ throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
+ } // END - if
+
+ // Set last controller
+ $this->setResolvedInstance($controllerInstance);
+
+ // Return the maybe resolved instance
+ return $controllerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A !!! protocol resolver class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 !!!ProtocolResolver extends BaseProtocolResolver implements ProtocolResolver, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of a !!! protocol resolver
+ *
+ * @return $resolverInstance The prepared command resolver instance
+ */
+ public static final function create!!!ProtocolResolver () {
+ // Create the new instance
+ $resolverInstance = new !!!ProtocolResolver();
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+
+ /**
+ * Returns an instance of a LocateableNode class for a given NodeHelper
+ * instance or null if it was not found.
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return $unlInstance An instance of a LocateableNode class
+ * @todo 0% done
+ */
+ public function resolveUniversalNodeLocatorFromNodeHelper (NodeHelper $nodeInstance) {
+ $this->partialStub('Please implement this method. nodeInstance=' . $nodeInstance->__toString());
+ }
+
+ /**
+ * Returns the UNL as string from given configuration key.
+ *
+ * @param $configKey Configuration key for UNL address (valid: internal,external)
+ * @return $unl Universal node locator
+ * @todo 90% done
+ */
+ public function resolveUniversalNodeLocatorFromConfigKey ($configKey) {
+ // Put all together
+ $unl = sprintf('%s://%s',
+ $this->getProtocolName(),
+ $this->getConfigInstance()->getConfigEntry($configKey . '_address')
+ );
+
+ /*
+ * And return it. Please note that e.g. a FaxProtocolResolver will
+ * return a different UNL and therefore all protocol resolvers must do
+ * it on their own way.
+ */
+ return $unl;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A generic protocol resolver class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseProtocolResolver extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TCP protocol resolver class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolver, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set protocol type
+ $this->setProtocolName('tcp');
+ }
+
+ /**
+ * Creates an instance of a TCP protocol resolver
+ *
+ * @return $resolverInstance The prepared command resolver instance
+ */
+ public static final function createTcpProtocolResolver () {
+ // Create the new instance
+ $resolverInstance = new TcpProtocolResolver();
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+
+ /**
+ * Returns an instance of a LocateableNode class for a given NodeHelper
+ * instance or null if it was not found.
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return $unlInstance An instance of a LocateableNode class
+ * @todo 0% done
+ */
+ public function resolveUniversalNodeLocatorFromNodeHelper (NodeHelper $nodeInstance) {
+ // Get search instance (to lookup database result)
+ $searchInstance = $nodeInstance->getSearchInstance();
+
+ // Make sure the in stance is valid
+ assert($searchInstance instanceof SearchCriteria);
+
+ // Refetch and rewind iterator
+ $resultInstance = $nodeInstance->getWrapperInstance()->doSelectByCriteria($searchInstance);
+
+ // Is the result valid?
+ if ((!$resultInstance->valid()) || (!$resultInstance->next())) {
+ // Node not found in database, this could mean that your database file is damaged.
+ return NULL;
+ } // END - if
+
+ // Get current entry
+ $current = $resultInstance->current();
+
+ // This should always be the case, if not your database file might be damaged.
+ assert($nodeInstance->getNodeId() == $current[NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID]);
+
+ // Get UNL instance and handle over all data
+ $unlInstance = ObjectFactory::createObjectByConfiguredName('universal_node_locator_class', array($current));
+
+ // Return resolved instance
+ return $unlInstance;
+ }
+
+ /**
+ * Returns the UNL as string from given configuration key.
+ *
+ * @param $configKey Configuration key for UNL address (valid: internal,external)
+ * @return $unl Universal node locator
+ */
+ public function resolveUniversalNodeLocatorFromConfigKey ($configKey) {
+ // Get address
+ $address = $this->getConfigInstance()->getConfigEntry($configKey . '_address');
+
+ // Is the address empty?
+ if (empty($address)) {
+ // Okay, then find it
+ switch ($configKey) {
+ case 'external': // External IP
+ $address = ConsoleTools::determineExternalAddress();
+ break;
+
+ case 'internal': // Internal IP
+ $address = ConsoleTools::acquireSelfIPAddress();
+ break;
+ } // END - switch
+ } // END - if
+
+ // Put all together
+ $unl = sprintf('%s://%s:%s',
+ $this->getProtocolName(),
+ $address,
+ $this->getConfigInstance()->getConfigEntry('node_listen_port')
+ );
+
+ /*
+ * And return it. Please note that e.g. a FaxProtocolResolver will
+ * return a different UNL and therefore all protocol resolvers must do
+ * it on their own way.
+ */
+ return $unl;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A generic state resolver class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseStateResolver extends BaseResolver {
+ /**
+ * Prefix for local, remote or other resolver
+ */
+ private $statePrefix = '';
+
+ /**
+ * Validated state name
+ */
+ private $stateName = '';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the real class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Setter for state prefix
+ *
+ * @param $statePrefix Last validated statePrefix
+ * @return void
+ */
+ protected final function setStatePrefix ($statePrefix) {
+ $this->statePrefix = $statePrefix;
+ }
+
+ /**
+ * Getter for state prefix
+ *
+ * @param $statePrefix Last validated statePrefix
+ * @return void
+ */
+ protected final function getStatePrefix () {
+ return $this->statePrefix;
+ }
+
+ /**
+ * Setter for state name
+ *
+ * @param $stateName Last validated state name
+ * @return void
+ */
+ protected final function setStateName ($stateName) {
+ $this->stateName = $stateName;
+ }
+
+ /**
+ * Getter for state name
+ *
+ * @return $stateName Last validated state name
+ */
+ public final function getStateName () {
+ return $this->stateName;
+ }
+
+ /**
+ * "Loads" a given state and instances it if not yet cached. If the
+ * state was not found an UnresolveableStateException is thrown
+ *
+ * @param $stateName A state name we shall look for
+ * @return $stateInstance A loaded state instance
+ * @throws UnresolveableStateException Thrown if even the requested
+ * state class is missing (bad!)
+ */
+ protected function loadState ($stateName) {
+ // Init state instance
+ $stateInstance = NULL;
+
+ // Create state class name
+ $className = $this->getStatePrefix() . '' . self::convertToClassName($stateName) . 'State';
+
+ // ... and set it
+ $this->setClassName($className);
+
+ // Is this class loaded?
+ if (!class_exists($this->getClassName())) {
+ // Throw an exception here
+ throw new UnresolveableStateException(array($this, $stateName), self::EXCEPTION_INVALID_STATE);
+ } // END - if
+
+ // Initialize the state
+ $stateInstance = ObjectFactory::createObjectByName(
+ $this->getClassName(),
+ array($this)
+ );
+
+ // Return the result
+ return $stateInstance;
+ }
+
+ /**
+ * Checks whether the given state is valid
+ *
+ * @param $stateName The default state we shall execute
+ * @return $isValid Whether the given state is valid
+ * @throws EmptyVariableException Thrown if given state is not set
+ * @throws DefaultStateException Thrown if default state was not found
+ */
+ public function isStateValid ($stateName) {
+ // By default nothing shall be valid
+ $isValid = FALSE;
+
+ // Is a state set?
+ if (empty($stateName)) {
+ // Then thrown an exception here
+ throw new EmptyVariableException(array($this, 'stateName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } // END - if
+
+ // Create class name
+ $className = $this->statePrefix . self::convertToClassName($stateName) . 'State';
+
+ // Now, let us create the full name of the state class
+ $this->setClassName($className);
+
+ // Try it hard to get an state
+ while ($isValid === FALSE) {
+ // Is this class already loaded?
+ if (class_exists($this->getClassName())) {
+ // This class does exist. :-)
+ $isValid = TRUE;
+ } elseif ($this->getClassName() != $this->statePrefix . 'DefaultState') {
+ // Set default state
+ $this->setClassName($this->statePrefix . 'DefaultState');
+ } else {
+ // All is tried, give it up here
+ throw new DefaultStateException($this, self::EXCEPTION_DEFAULT_STATE_GONE);
+ }
+ } // END - while
+
+ // Return the result
+ return $isValid;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A resolver for resolving peer states locally
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PeerStateResolver extends BaseStateResolver implements StateResolver {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set prefix to 'Peer'
+ $this->setStatePrefix('Peer');
+ }
+
+ /**
+ * Creates an instance of a resolver class with a given state
+ *
+ * @return $resolverInstance The prepared state resolver instance
+ */
+ public static final function createPeerStateResolver () {
+ // Create the new instance
+ $resolverInstance = new PeerStateResolver();
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+
+ /**
+ * Returns an state instance for a given raw package data and socket resource
+ *
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @param $packageData Raw package data
+ * @param $socketResource A valid socket resource
+ * @return $stateInstance An instance of the resolved state
+ * @throws InvalidSocketException If socketResource, even from getSocketResource() is no valid resource
+ * @todo ~30% done
+ */
+ public static function resolveStateByPackage (ConnectionHelper $helperInstance, array $packageData, $socketResource) {
+ // Get temporary resolver instance
+ $resolverInstance = self::createPeerStateResolver();
+
+ // Init state instance
+ $stateInstance = NULL;
+
+ // Is the socket resource valid?
+ if (!is_resource($socketResource)) {
+ // No, so get socket resource from helper
+ $socketResource = $helperInstance->getSocketResource();
+
+ // Still no socket resource?
+ if (!is_resource($socketResource)) {
+ // Then abort here with an exception (may happen after socket_shutdown())
+ throw new InvalidSocketException(array($helperInstance, $socketResource, 'unknown', 'unknown'), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+ } // END - if
+
+ // Get error code from it
+ $errorCode = socket_last_error($socketResource);
+
+ // Translate the error code to an own name
+ $errorCode = $helperInstance->translateSocketErrorCodeToName($errorCode);
+
+ // Create a state instance based on $errorCode. This factory does the hard work for us
+ $stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageData, $socketResource, $errorCode);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? scanner class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Scanner extends BaseScanner implements Scanner, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $scannerInstance An instance of a Scanner class
+ */
+ public final static function create???Scanner () {
+ // Get new instance
+ $scannerInstance = new ???Scanner();
+
+ // Return the prepared instance
+ return $scannerInstance;
+ }
+
+ /**
+ * Runs the scanner (please no loops here)
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function execute () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Scanner class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 BaseScanner extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? scanner class for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Crawler???Scanner extends BaseScanner implements Scanner, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $scannerInstance An instance of a Scanner class
+ */
+ public final static function createCrawler???Scanner () {
+ // Get new instance
+ $scannerInstance = new Crawler???Scanner();
+
+ // Return the prepared instance
+ return $scannerInstance;
+ }
+
+ /**
+ * Runs the scanner (please no loops here)
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function execute () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A UploadedList scanner class for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerUploadedListScanner extends BaseScanner implements Scanner, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $scannerInstance An instance of a Scanner class
+ */
+ public final static function createCrawlerUploadedListScanner () {
+ // Get new instance
+ $scannerInstance = new CrawlerUploadedListScanner();
+
+ // Return the prepared instance
+ return $scannerInstance;
+ }
+
+ /**
+ * Runs the scanner (please no loops here)
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function execute () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? source class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Source extends BaseSource implements Source!!! {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $sourceInstance An instance of a Source class
+ */
+ public final static function create???Source () {
+ // Get new instance
+ $sourceInstance = new ???Source();
+
+ // Return the prepared instance
+ return $sourceInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Source class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseSource extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general URL source class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseUrlSource extends BaseSource {
+ // Stack name for all URLs
+ const STACKER_NAME_URLS = 'urls';
+
+ // Array elements for CSV data array
+ const CRAWL_JOB_ARRAY_START_URL = 'start_url';
+ const CRAWL_JOB_ARRAY_DEPTH = 'start_depth';
+ const CRAWL_JOB_ARRAY_EXTERNAL_DEPTH = 'external_depth';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Initalizes this source
+ *
+ * @param $prefix Prefix for this source
+ * @param $sourceName Name of this source
+ * @return void
+ */
+ protected function initSource ($prefix, $sourceName) {
+ // Use another object factory
+ $stackInstance = FileStackFactory::createFileStackInstance($prefix . '_url', $sourceName);
+
+ // Set the stack here
+ $this->setStackInstance($stackInstance);
+ }
+
+ /**
+ * Determines whether the stack 'urls' is empty.
+ *
+ * @return $isEmpty Whether the stack 'urls' is empty.
+ */
+ public function isUrlStackEmpty () {
+ // Determine it
+ $isEmpty = $this->getStackInstance()->isStackEmpty(self::STACKER_NAME_URLS);
+
+ // Return result
+ return $isEmpty;
+ }
+
+ /**
+ * Enriches the given associative array with more data, now at least 2
+ * elements are required:
+ *
+ * 'start_url' - Starting URL
+ * 'start_depth' - Crawl depth for starting URL
+ *
+ * @param $crawlData Array with partial data for being queued
+ * @return void
+ * @todo ~10% done
+ */
+ protected function enrichCrawlerQueueData (array &$crawlData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: crawlData()=' . count($crawlData) . ' - CALLED!');
+
+ // Check for minimum array elements
+ assert(isset($crawlData[self::CRAWL_JOB_ARRAY_START_URL]));
+ assert(isset($crawlData[self::CRAWL_JOB_ARRAY_DEPTH]));
+
+ // @TODO Add more elements
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Enqueues given crawler array in assigned file-based stack
+ *
+ * @param $crawlData Array with partial data for being queued
+ * @return void
+ */
+ protected function enqueueInFileStack (array $crawlData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: crawlData()=' . count($crawlData) . ' - CALLED!');
+
+ // Get the stack instance and enqueue it
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_URLS, $crawlData);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A TestUnit source class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TestUnitSource extends BaseSource implements UnitSource, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $sourceInstance An instance of a Source class
+ */
+ public final static function createTestUnitSource () {
+ // Get new instance
+ $sourceInstance = new TestUnitSource();
+
+ // Create a RNG instance and set it in this class
+ $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+ $sourceInstance->setRngInstance($rngInstance);
+
+ // And also a crypto instance (for our encrypted messages)
+ $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+ $sourceInstance->setCryptoInstance($cryptoInstance);
+
+ // Return the prepared instance
+ return $sourceInstance;
+ }
+
+ /**
+ * Generates an encrypted random message
+ *
+ * @return $encryptedMessage The encrypted random message
+ */
+ public function generateMessageFromSource () {
+ // Get a very secret message by encoding and random string with BASE64
+ $secretMessage = base64_encode($this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_message_length')));
+
+ // Get a random, secret key
+ $secretKey = $this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('test_unit_random_secret_key_length') / 8);
+
+ // Now encrypt the message with our key and a good (strong) cipher
+ $encryptedMessage = base64_encode($this->getCryptoInstance()->encryptString($secretMessage, $secretKey));
+
+ // Return it
+ return $encryptedMessage;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? URL source class for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Crawler???UrlSource extends BaseUrlSource implements UrlSource, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $sourceInstance An instance of a Source class
+ */
+ public final static function createCrawler???UrlSource () {
+ // Get new instance
+ $sourceInstance = new Crawler???UrlSource();
+
+ // Init source
+ $sourceInstance->initSource('crawler', '!!!');
+
+ // Return the prepared instance
+ return $sourceInstance;
+ }
+
+ /**
+ * Processes entries in the stack.
+ *
+ * @return void
+ * @todo ~ 10% done
+ */
+ public function processStack () {
+ // Does the stack have some entries left?
+ if ($this->isUrlStackEmpty()) {
+ // Nothing to handle here
+ return;
+ } // END - if
+
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A FoundRss URL source class for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerFoundRssUrlSource extends BaseUrlSource implements UrlSource, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $sourceInstance An instance of a Source class
+ */
+ public final static function createCrawlerFoundRssUrlSource () {
+ // Get new instance
+ $sourceInstance = new CrawlerFoundRssUrlSource();
+
+ // Init source
+ $sourceInstance->initSource('crawler', 'found_rss');
+
+ // Return the prepared instance
+ return $sourceInstance;
+ }
+
+ /**
+ * Fills the URL stack with new entries from source
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function fillUrlStack () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? URL source class for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerLocalStartUrlSource extends BaseUrlSource implements UrlSource, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $sourceInstance An instance of a Source class
+ */
+ public final static function createCrawlerLocalStartUrlSource () {
+ // Get new instance
+ $sourceInstance = new CrawlerLocalStartUrlSource();
+
+ // Init source
+ $sourceInstance->initSource('crawler', 'local_start');
+
+ // Return the prepared instance
+ return $sourceInstance;
+ }
+
+ /**
+ * Fills the URL stack with new entries from source
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function fillUrlStack () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A RssStart URL source class for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerRssStartUrlSource extends BaseUrlSource implements UrlSource, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $sourceInstance An instance of a Source class
+ */
+ public final static function createCrawlerRssStartUrlSource () {
+ // Get new instance
+ $sourceInstance = new CrawlerRssStartUrlSource();
+
+ // Init source
+ $sourceInstance->initSource('crawler', 'rss_start');
+
+ // Return the prepared instance
+ return $sourceInstance;
+ }
+
+ /**
+ * Fills the URL stack with new entries from source
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function fillUrlStack () {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A UploadedList URL source class for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, Registerable {
+ /**
+ * Stack name for a CSV file
+ */
+ const STACK_NAME_CSV_FILE = 'csv_file';
+
+ /**
+ * Stack name for a CSV entry
+ */
+ const STACK_NAME_CSV_ENTRY = 'csv_entry';
+
+ /**
+ * Size of crawl (CSV) entry which is an indexed array:
+ *
+ * 0 = URL to crawl
+ * 1 = Crawl depth of URL
+ * 2 = Crawl depth of linked URLs (same other host only)
+ */
+ const CRAWL_ENTRY_SIZE = 3;
+
+ /**
+ * "Cached" CSV path
+ */
+ private $csvFilePath = '';
+
+ /**
+ * Last CSV file instance
+ */
+ private $lastCsvFileInstance = NULL;
+
+ /**
+ * Stack for pushing data from this clas to another
+ */
+ private $stackSourceInstance = NULL;
+
+ /**
+ * "Imported" CSV files
+ */
+ private $csvFileImported = array();
+
+ /**
+ * "Cached" separator for columns
+ */
+ private $columnSeparator = '';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // "Cache" CSV path for faster usage
+ $this->csvFilePath = $this->getConfigInstance()->getConfigEntry('base_path') . '/' . $this->getConfigInstance()->getConfigEntry('crawler_csv_file_path');
+
+ // Initialize directory instance
+ $directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($this->csvFilePath));
+
+ // Set it here
+ $this->setDirectoryInstance($directoryInstance);
+
+ // Init stack instance
+ $this->stackSourceInstance = ObjectFactory::createObjectByConfiguredName('crawler_uploaded_list_url_source_stack_class');
+
+ // Init stacks
+ $this->getStackSourceInstance()->initStack(self::STACK_NAME_CSV_FILE);
+ $this->getStackSourceInstance()->initStack(self::STACK_NAME_CSV_ENTRY);
+
+ // "Cache" column separator
+ $this->columnSeparator = $this->getConfigInstance()->getConfigEntry('crawler_url_list_column_separator');
+ }
+
+ /**
+ * Checks whether a CSV file is found in configured path
+ *
+ * @return $isFound Whether a CSV file is found
+ */
+ private function isCsvFileFound () {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is it valid?
+ if (!$this->getDirectoryInstance()->getDirectoryIteratorInstance()->valid()) {
+ // Rewind to start
+ $this->getDirectoryInstance()->getDirectoryIteratorInstance()->rewind();
+ } // END - if
+
+ // Read next entry
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: this->csvFileImported=' . print_r($this->csvFileImported, TRUE));
+ $directoryEntry = $this->getDirectoryInstance()->readDirectoryExcept(array_merge(array('.htaccess', '.', '..'), $this->csvFileImported));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE[' . __METHOD__ . ':' . __LINE__ . '] directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry);
+
+ // Is it empty or wrong file extension?
+ if ((empty($directoryEntry)) || (substr($directoryEntry, -4, 4) != '.csv')) {
+ // Skip further processing
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE[' . __METHOD__ . ':' . __LINE__ . '] directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry . ' - SKIPPED!');
+ return FALSE;
+ } // END - if
+
+ // Initialize CSV file instance
+ $this->lastCsvFileInstance = ObjectFactory::createObjectByConfiguredName('csv_input_file_class', array($this->csvFilePath . '/' . $directoryEntry));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . '] directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry . ' - Instance created - EXIT!');
+
+ // Found an entry
+ return TRUE;
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $sourceInstance An instance of a Source class
+ */
+ public final static function createCrawlerUploadedListUrlSource () {
+ // Get new instance
+ $sourceInstance = new CrawlerUploadedListUrlSource();
+
+ // Init source
+ $sourceInstance->initSource('crawler', 'uploaded_list');
+
+ // Return the prepared instance
+ return $sourceInstance;
+ }
+
+ /**
+ * Enriches and saves the given CSV entry (array) in the assigned
+ * file-based stack. To such entry a lot more informations are added, such
+ * as which files shall be crawled and many more.
+ *
+ * @param $csvData Array with data from a CSV file
+ * @return void
+ */
+ private function saveCsvDataInCrawlerQueue (array $csvData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvData()=' . count($csvData) . ' - CALLED!');
+
+ // The array must have a fixed amount of elements, later enhancements may accept more
+ assert(count($csvData) == self::CRAWL_ENTRY_SIZE);
+
+ /*
+ * First converted the indexed array into an assoziative array. Don't
+ * forget to expand this array as well when you want to add another
+ * column to the CSV file.
+ */
+ $csvArray = array(
+ self::CRAWL_JOB_ARRAY_START_URL => $csvData[0],
+ self::CRAWL_JOB_ARRAY_DEPTH => $csvData[1],
+ self::CRAWL_JOB_ARRAY_EXTERNAL_DEPTH => $csvData[2]
+ );
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvArray()=' . count($csvArray) . ' - BEFORE!');
+
+ // Then add more data to it
+ $this->enrichCrawlerQueueData($csvArray);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvArray()=' . count($csvArray) . ' - AFTER!');
+
+ /*
+ * Then enqueue it in the file stack. The local crawler "task" will
+ * then pick this up.
+ */
+ $this->enqueueInFileStack($csvArray);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Checks whether a CSV file has been loaded (added to the stack)
+ *
+ * @return $isAdded Whether a CSV file has been loaded
+ */
+ private function isCsvFileAdded () {
+ // Check whether the stacker is not empty
+ $isAdded = (($this->getStackSourceInstance()->isStackInitialized(self::STACK_NAME_CSV_FILE)) && (!$this->getStackSourceInstance()->isStackEmpty(self::STACK_NAME_CSV_FILE)));
+
+ // Return the result
+ return $isAdded;
+ }
+
+ /**
+ * Checks whether a CSV entry has been added to the stack
+ *
+ * @return $isAdded Whether a CSV entry has been added
+ */
+ private function isCsvEntryAdded () {
+ // Check whether the stacker is not empty
+ $isAdded = (($this->getStackSourceInstance()->isStackInitialized(self::STACK_NAME_CSV_ENTRY)) && (!$this->getStackSourceInstance()->isStackEmpty(self::STACK_NAME_CSV_ENTRY)));
+
+ // Return the result
+ return $isAdded;
+ }
+
+ /**
+ * Initializes the import of the CSV file which is being processed by other task
+ *
+ * @return void
+ * @throws NullPointerException If lastCsvFileInstance is not set
+ */
+ private function addCsvFile () {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is the instance set?
+ if (is_null($this->lastCsvFileInstance)) {
+ // This should not happen
+ throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ } // END - if
+
+ // Stack this file
+ $this->getStackSourceInstance()->pushNamed(self::STACK_NAME_CSV_FILE, $this->lastCsvFileInstance);
+
+ // ... and mark it as "imported"
+ array_push($this->csvFileImported, basename($this->lastCsvFileInstance->getFileName()));
+
+ // ... and finally NULL it (to save some RAM)
+ $this->lastCsvFileInstance = NULL;
+
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Parses the next stacked CSV file by reading only one line from it. Then
+ * the read line is being validated and if found good being feed to the next
+ * stack. The file is removed from stack only if it has been fully parsed.
+ *
+ * @return void
+ */
+ private function parseCsvFile () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Get next entry
+ $csvFileInstance = $this->getStackSourceInstance()->popNamed(self::STACK_NAME_CSV_FILE);
+
+ // Read full "CSV line"
+ $csvData = $csvFileInstance->readCsvFileLine($this->columnSeparator);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvData[' . gettype($csvData) . ']=' . print_r($csvData, TRUE));
+
+ // Expect always an array
+ assert(is_array($csvData));
+
+ // Is the array empty?
+ if (count($csvData) == 0) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: File ' . $csvFileInstance->getFileName() . ' has been fully read.');
+
+ // Try to close it by actually unsetting (destructing) it
+ unset($csvFileInstance);
+
+ // This file as been fully read, so don't push it back on stack.
+ return;
+ } // END - if
+
+ // ... with a fixed amount of elements, later enhancements may accept more
+ assert(count($csvData) == self::CRAWL_ENTRY_SIZE);
+
+ /*
+ * Push the file back on stack as it may contain more entries. This way
+ * all files got rotated on stack which may improve crawler performance.
+ */
+ $this->getStackSourceInstance()->pushNamed(self::STACK_NAME_CSV_FILE, $csvFileInstance);
+
+ // Push array on next stack
+ $this->getStackSourceInstance()->pushNamed(self::STACK_NAME_CSV_ENTRY, $csvData);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Parses the next stacked CSV entry.
+ *
+ * @return void
+ */
+ private function parseCsvEntry () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Pop it from stack
+ $csvData = $this->getStackSourceInstance()->popNamed(self::STACK_NAME_CSV_ENTRY);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvData[' . gettype($csvData) . ']=' . print_r($csvData, TRUE));
+
+ // It must have a fixed amount of elements (see method parseCsvFile() for details)
+ assert(count($csvData) == self::CRAWL_ENTRY_SIZE);
+
+ // Save it in crawler queue (which will enrich it with way more informations
+ $this->saveCsvDataInCrawlerQueue($csvData);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Getter for stackSourceInstance variable
+ *
+ * @return $stackSourceInstance An instance of an additional stack
+ */
+ public final function getStackSourceInstance () {
+ return $this->stackSourceInstance;
+ }
+
+ /**
+ * Fills the URL stack with new entries from source
+ *
+ * @return void
+ * @todo ~40% done
+ */
+ public function fillUrlStack () {
+ // Does the stack have some entries left?
+ if ($this->isCsvEntryAdded()) {
+ /*
+ * A CSV file has been found and "imported" (added to stack). Now
+ * the file can be read line by line and checked every one of it.
+ */
+ $this->parseCsvEntry();
+ } elseif ($this->isCsvFileAdded()) {
+ /*
+ * A CSV file has been found and "imported" (added to stack). Now
+ * the file can be read line by line and checked every one of it.
+ */
+ $this->parseCsvFile();
+ } elseif ($this->isCsvFileFound()) {
+ /*
+ * A file containing an URL list is found. Please note the format is
+ * CSV-like as you may wish to provide meta data such as crawl
+ * depth, handling of 3rd-party URLs and such.
+ */
+ $this->addCsvFile();
+ }
+
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A active communicator state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CommunicatorActiveState extends BaseCommunicatorState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructo
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('active');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $communicatorInstance An instance of a Communicator class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createCommunicatorActiveState (Communicator $communicatorInstance) {
+ // Get new instance
+ $stateInstance = new CommunicatorActiveState();
+
+ // Set the communicator instance
+ $stateInstance->setCommunicatorInstance($communicatorInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? communicator state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014, 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Communicator???State extends BaseCommunicatorState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('!!!');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $communicatorInstance An instance of a Communicator class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createCommunicator???State (Communicator $communicatorInstance) {
+ // Get new instance
+ $stateInstance = new Communicator???State();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('COMMUNICATOR-STATE: Has changed from ' . $communicatorInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the communicator instance
+ $stateInstance->setCommunicatorInstance($communicatorInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general communicator state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014, 2015 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 BaseCommunicatorState extends BaseState {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Validates whether the state is 'active' or throws an exception if
+ * it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'active'
+ */
+ public function validateCommunicatorStateIsActive () {
+ // Just compare it...
+ if (!$this instanceof CommunicatorActiveState) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A init communicator state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CommunicatorInitState extends BaseCommunicatorState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructo
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('init');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $communicatorInstance An instance of a Communicator class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createCommunicatorInitState (Communicator $communicatorInstance) {
+ // Get new instance
+ $stateInstance = new CommunicatorInitState();
+
+ // Set the communicator instance
+ $stateInstance->setCommunicatorInstance($communicatorInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ * @todo 0% done?
+ */
+ public function executeState (Executor $executorInstance) {
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A active crawler state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CrawlerActiveState extends BaseCrawlerState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructo
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('active');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $crawlerInstance An instance of a Crawler class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createCrawlerActiveState () {
+ // Get new instance
+ $stateInstance = new CrawlerActiveState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ * @todo 0% done
+ */
+ public function executeState (Executor $executorInstance) {
+ $this->partialStub('Unfinished method, executorInstance=' . $executorInstance->__toString());
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+
+ /**
+ * State change if the communicator has fully initialized.
+ *
+ * @return void
+ * @todo ~30% done
+ */
+ public function communicatorHasInitialized () {
+ // Please implement
+ $this->partialStub('Unfinished method.');
+
+ // Change state to 'active'
+ CrawlerStateFactory::createCrawlerStateInstanceByName('active');
+ }
--- /dev/null
+<?php
+/**
+ * A booting crawler state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CrawlerBootingState extends BaseCrawlerState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructo
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('booting');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createCrawlerBootingState () {
+ // Get new instance
+ $stateInstance = new CrawlerBootingState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ * @todo 0% done
+ */
+ public function executeState (Executor $executorInstance) {
+ $this->partialStub('Unfinished method, executorInstance=' . $executorInstance->__toString());
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? crawler state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Crawler???State extends BaseCrawlerState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('!!!');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $crawlerInstance An instance of a Crawler class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createCrawler???State (Crawler $crawlerInstance) {
+ // Get new instance
+ $stateInstance = new Crawler???State();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('COMMUNICATOR-STATE: Has changed from ' . $crawlerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the crawler instance
+ $stateInstance->setCrawlerInstance($crawlerInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general crawler state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler 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 BaseCrawlerState extends BaseState {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Validates whether the state is 'active' or throws an exception if
+ * it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'active'
+ */
+ public function validateCrawlerStateIsActive () {
+ // Just compare it...
+ if (!$this instanceof CrawlerActiveState) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A init crawler state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CrawlerInitState extends BaseCrawlerState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructo
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('init');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createCrawlerInitState () {
+ // Get new instance
+ $stateInstance = new CrawlerInitState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ */
+ public function executeState (Executor $executorInstance) {
+ // Initialize the executor (can be a Communicator instance)
+ $executorInstance->initExecutor($this);
+ }
+
+ /**
+ * State change if the communicator has fully initialized.
+ *
+ * @return void
+ * @todo ~30% done
+ */
+ public function communicatorHasInitialized () {
+ // Please implement
+ $this->partialStub('Unfinished method.');
+
+ // Change state to 'booting'
+ CrawlerStateFactory::createCrawlerStateInstanceByName('booting');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? cruncher state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Cruncher Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Cruncher???State extends BaseCruncherState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('!!!');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $cruncherInstance An instance of a CruncherHelper class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createCruncher???State (CruncherHelper $cruncherInstance) {
+ // Get new instance
+ $stateInstance = new Cruncher???State();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER-STATE: Has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the cruncher instance
+ $stateInstance->setCruncherInstance($cruncherInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ */
+ public function executeState (Executor $executorInstance) {
+ $this->partialStub('This state needs implementation. executorInstance=' . $executorInstance->__toString());
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general cruncher state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 BaseCruncherState extends BaseState {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Validates whether the state is 'active' or throws an exception if
+ * it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'active'
+ */
+ public function validateCruncherStateIsActive () {
+ // Just compare it...
+ if (!$this instanceof CruncherActiveState) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
+ /**
+ * Checks if this state is 'virgin'
+ *
+ * @return $isVirgin Whether this state is 'virgin'
+ */
+ public function isCruncherStateVirgin () {
+ // Just compare it...
+ return ($this instanceof CruncherVirginState);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Init cruncher state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherInitState extends BaseCruncherState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('init');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createCruncherInitState () {
+ // Get new instance
+ $stateInstance = new CruncherInitState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ */
+ public function executeState (Executor $executorInstance) {
+ // Initialize the unit production to maybe become 'virgin' or 'active' if work/test units are there
+ $executorInstance->initUnitProduction($this);
+ }
+
+ /**
+ * An encrypted message has been generated so we change the state to
+ * 'virgin'.
+ *
+ * @return void
+ */
+ public function encryptedMessageGenerated () {
+ // Change the state now to 'virgin'
+ CruncherStateFactory::createCruncherStateInstanceByName('virgin');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Virgin cruncher state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherVirginState extends BaseCruncherState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('virgin');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createCruncherVirginState () {
+ // Get new instance
+ $stateInstance = new CruncherVirginState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ */
+ public function executeState (Executor $executorInstance) {
+ // Produce some keys now
+ $executorInstance->produceKeys($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Active dht state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtActiveState extends BaseDhtState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('active');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $dhtInstance An instance of a Distributable class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createDhtActiveState (Distributable $dhtInstance) {
+ // Get new instance
+ $stateInstance = new DhtActiveState();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE[' . __METHOD__ . ':' . __LINE__ . ']: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the dht instance
+ $stateInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Booting dht state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtBootingState extends BaseDhtState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('booting');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $dhtInstance An instance of a Distributable class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createDhtBootingState (Distributable $dhtInstance) {
+ // Get new instance
+ $stateInstance = new DhtBootingState();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE[' . __METHOD__ . ':' . __LINE__ . ']: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the dht instance
+ $stateInstance->setDhtInstance($dhtInstance);
+
+ // Get node instance and enable DHT bootstrap requests
+ NodeObjectFactory::createNodeInstance()->enableAcceptDhtBootstrap();
+
+ // Update DHT node info as well
+ $dhtInstance->enableAcceptDhtBootstrap();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? dht state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Dht???State extends BaseDhtState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('!!!');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $dhtInstance An instance of a Distributable class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createDht???State (Distributable $dhtInstance) {
+ // Get new instance
+ $stateInstance = new Dht???State();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the dht instance
+ $stateInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general DHT state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Create generic DHT interface
+ *
+ * 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 BaseDhtState extends BaseState {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Validates whether the DHT state is 'virgin' or throws an exception if it
+ * is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'virgin'
+ */
+ public function validateDhtStateIsVirginOrInit () {
+ // Just compare it...
+ if ((!$this instanceof DhtVirginState) && (!$this instanceof DhtInitState)) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
+ /**
+ * Checks whether the DHT's state is 'booting' by comparing it with the
+ * state's class name.
+ *
+ * @return $isBooting Whether this DHT's state is 'booting'
+ */
+ public function ifDhtIsBooting () {
+ // Check state
+ $isBooting = ($this instanceof DhtBootingState);
+
+ // Return status
+ return $isBooting;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Init dht state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtInitState extends BaseDhtState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('init');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $dhtInstance An instance of a Distributable class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createDhtInitState (Distributable $dhtInstance) {
+ // Get new instance
+ $stateInstance = new DhtInitState();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE[' . __METHOD__ . ':' . __LINE__ . ']: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the dht instance
+ $stateInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * The DHT has been initialized. This means that the state can be changed
+ * to the next one: virgin.
+ *
+ * @return void
+ */
+ public function dhtHasInitialized () {
+ // Create a new instance
+ DhtStateFactory::createDhtStateInstanceByName('virgin', $this->getDhtInstance());
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Virgin dht state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtVirginState extends BaseDhtState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('virgin');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $dhtInstance An instance of a Distributable class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createDhtVirginState (Distributable $dhtInstance) {
+ // Get new instance
+ $stateInstance = new DhtVirginState();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE[' . __METHOD__ . ':' . __LINE__ . ']: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the dht instance
+ $stateInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Called when the DHT is booting. This means that the bootstrap message
+ * has been queued.
+ *
+ * @return void
+ */
+ public function dhtIsBooting () {
+ // Get new instance and set it
+ DhtStateFactory::createDhtStateInstanceByName('booting', $this->getDhtInstance());
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Booting miner state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 MinerBootingState extends BaseMinerState implements Stateable {
+ /**
+ * Array of booted producers
+ */
+ private $bootedProducer = array();
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('booting');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createMinerBootingState () {
+ // Get new instance
+ $stateInstance = new MinerBootingState();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Has changed from ' . $minerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ */
+ public function executeState (Executor $executorInstance) {
+ // Has this executor (producer) run?
+ if (isset($this->bootedProducer[$executorInstance->__toString()])) {
+ // Then silently skip this
+ return;
+ } // END - if
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Calling prepareBlockProduction() on ' . $executorInstance->__toString() . ' ...');
+
+ // Now prepare the unit production to maybe become 'virgin' or 'active' if work/test units are there
+ $executorInstance->prepareBlockProduction($this);
+
+ // Mark producer as booted
+ $this->bootedProducer[$executorInstance->__toString()] = TRUE;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general miner state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 BaseMinerState extends BaseState {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Validates whether the state is 'active' or throws an exception if
+ * it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'active'
+ */
+ public function validateMinerStateIsActive () {
+ // Just compare it...
+ if (!$this instanceof MinerActiveState) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
+ /**
+ * Validates whether the state is 'init' or throws an exception if
+ * it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'init'
+ */
+ public function validateMinerStateIsInit () {
+ // Just compare it...
+ if (!$this instanceof MinerInitState) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
+ /**
+ * Validates whether the state is 'booting' or throws an exception if
+ * it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'booting'
+ */
+ public function validateMinerStateIsBooting () {
+ // Just compare it...
+ if (!$this instanceof MinerBootingState) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
+ /**
+ * Checks if this state is 'virgin'
+ *
+ * @return $isVirgin Whether this state is 'virgin'
+ */
+ public function isMinerStateVirgin () {
+ // Just compare it...
+ return ($this instanceof MinerVirginState);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? miner state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Miner???State extends BaseMinerState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('!!!');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $minerInstance An instance of a MinerHelper class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createMiner???State (MinerHelper $minerInstance) {
+ // Get new instance
+ $stateInstance = new Miner???State();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Has changed from ' . $minerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the miner instance
+ $stateInstance->setMinerInstance($minerInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ */
+ public function executeState (Executor $executorInstance) {
+ $this->partialStub('This state needs implementation. executorInstance=' . $executorInstance->__toString());
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Init miner state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Miner 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 MinerInitState extends BaseMinerState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('init');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createMinerInitState () {
+ // Get new instance
+ $stateInstance = new MinerInitState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ * @todo 0% done?
+ */
+ public function executeState (Executor $executorInstance) {
+ }
+
+ /**
+ * An encrypted message has been generated so we change the state to
+ * 'virgin'.
+ *
+ * @return void
+ */
+ public function encryptedMessageGenerated () {
+ // Change the state now to 'virgin'
+ MinerStateFactory::createMinerStateInstanceByName('virgin');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Virgin miner state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerVirginState extends BaseMinerState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('virgin');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createMinerVirginState () {
+ // Get new instance
+ $stateInstance = new MinerVirginState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ */
+ public function executeState (Executor $executorInstance) {
+ // Produce some keys now
+ $executorInstance->produceKeys($this);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An active node state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeActiveState extends BaseNodeState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('active');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createNodeActiveState () {
+ // Get new instance
+ $stateInstance = new NodeActiveState();
+
+ // Get node instance and set 'active' flag
+ NodeObjectFactory::createNodeInstance()->enableIsActive();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * State change for if the node got announced to it's upper hubs
+ *
+ * @return void
+ */
+ public function nodeAnnouncingToUpperHubs () {
+ // Create the new state instance
+ NodeStateFactory::createNodeStateInstanceByName('announcing');
+ }
+
+ /**
+ * State change for if the node has just connected to itself and
+ * node/session id are both equal. The self-connect means that
+ * the node possibly reachable from outside. This may require
+ * confirmation by other peers.
+ *
+ * @return void
+ * @todo We might want to move some calls to this method to fill it with life
+ */
+ public function nodeHasSelfConnected () {
+ // Create the new state instance
+ NodeStateFactory::createNodeStateInstanceByName('reachable');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A AnnouncementCompleted node state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeAnnouncementCompletedState extends BaseNodeState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('announcement_completed');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createNodeAnnouncementCompletedState () {
+ // Get new instance
+ $stateInstance = new NodeAnnouncementCompletedState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [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 - 2015 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
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createNodeAnnouncingState () {
+ // Get new instance
+ $stateInstance = new NodeAnnouncingState();
+
+ // 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');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? node state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Node???State extends BaseNodeState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('!!!');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createNode???State (NodeHelper $nodeInstance) {
+ // Get new instance
+ $stateInstance = new Node???State();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+ // Set the node instance
+ $stateInstance->setNodeInstance($nodeInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general node state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseNodeState extends BaseState {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Validates whether the state is 'active' or throws an exception if
+ * it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'active'
+ */
+ public function validateNodeStateIsActive () {
+ // Just compare it...
+ if (!$this instanceof NodeActiveState) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
+ /**
+ * Validates whether the state is 'active' or 'announcing' or throws an
+ * exception if it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'active' and not 'announcing'
+ */
+ public function validateNodeStateIsActiveOrAnnouncing () {
+ // Just compare it...
+ if ((!$this instanceof NodeActiveState) && (!$this instanceof NodeAnnouncingState)) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
+ /**
+ * Validates whether the state is 'active' or 'reachable' or throws an
+ * exception if it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'active' and not 'reachable'
+ */
+ public function validateNodeStateIsActiveOrReachable () {
+ // Just compare it...
+ if ((!$this instanceof NodeActiveState) && (!$this instanceof NodeReachableState)) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
+ /**
+ * Validates if the state is 'announcement_completed' or throws an
+ * exception if it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'active' and not 'announcing'
+ */
+ public function validateNodeStateIsAnnouncementCompleted () {
+ // Just compare it...
+ if (!$this instanceof NodeAnnouncementCompletedState) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A init node state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeInitState extends BaseNodeState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructo
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('init');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createNodeInitState () {
+ // Get new instance
+ $stateInstance = new NodeInitState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * State change for if the node has just generated a session id. This makes
+ * nodes with current state 'init' now 'virgin'.
+ *
+ * @return void
+ * @todo We might want to move some calls to this method to fill it with life
+ */
+ public function nodeGeneratedSessionId () {
+ // Create the new state instance
+ NodeStateFactory::createNodeStateInstanceByName('virgin');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Reachable node state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeReachableState extends BaseNodeState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('reachable');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public final static function createNodeReachableState () {
+ // Get new instance
+ $stateInstance = new NodeReachableState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * State change for if the node got announced to it's upper hubs
+ *
+ * @return void
+ */
+ public function nodeAnnouncingToUpperHubs () {
+ // Create the new state instance
+ NodeStateFactory::createNodeStateInstanceByName('announcing');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A virgin node state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeVirginState extends BaseNodeState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('virgin');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createNodeVirginState () {
+ // Get new instance
+ $stateInstance = new NodeVirginState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Change the state to 'active' when the hub has initialized all
+ * listeners, tasks, queues, etc. An active hub does not imply that it
+ * can be reached from outside so we have to deal with that state with
+ * yet another state class.
+ *
+ * @return void
+ */
+ public function nodeIsActivated () {
+ // Create the new state instance
+ NodeStateFactory::createNodeStateInstanceByName('active');
+ }
+
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? peer state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???PeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_!!!);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function create???PeerState () {
+ // Get new instance
+ $stateInstance = new ???PeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general peer state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BasePeerState extends BaseState {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Validates whether the state is 'connected' or throws an exception if
+ * it is every other state.
+ *
+ * @return void
+ * @throws UnexpectedStateException If the state is not 'connected'
+ */
+ public function validatePeerStateConnected () {
+ // Just compare it...
+ if (!$this->isPeerStateConnected()) {
+ // Throw the exception
+ throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
+ /**
+ * Checks whether the peer's state is 'connected'
+ *
+ * @return $isConnected Whether the state is 'connected'
+ */
+ public function isPeerStateConnected () {
+ // Just compare it...
+ return ($this instanceof ConnectedPeerState);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Connected peer state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ConnectedPeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName(BaseRawDataHandler::SOCKET_CONNECTED);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function createConnectedPeerState () {
+ // Get new instance
+ $stateInstance = new ConnectedPeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ConnectionRefused peer state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ConnectionRefusedPeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function createConnectionRefusedPeerState () {
+ // Get new instance
+ $stateInstance = new ConnectionRefusedPeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ConnectionTimedOut peer state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ConnectionTimedOutPeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_CONNECTION_TIMED_OUT);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function createConnectionTimedOutPeerState () {
+ // Get new instance
+ $stateInstance = new ConnectionTimedOutPeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A NoRouteToHost peer state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NoRouteToHostPeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_NO_ROUTE_TO_HOST);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function createNoRouteToHostPeerState () {
+ // Get new instance
+ $stateInstance = new NoRouteToHostPeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A OperationAlreadyProgress peer state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 OperationAlreadyProgressPeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function createOperationAlreadyProgressPeerState () {
+ // Get new instance
+ $stateInstance = new OperationAlreadyProgressPeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A Problem peer state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ProblemPeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_UNKNOWN);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function createProblemPeerState () {
+ // Get new instance
+ $stateInstance = new ProblemPeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A TransportEndpointGone peer state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TransportEndpointGonePeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function createTransportEndpointGonePeerState () {
+ // Get new instance
+ $stateInstance = new TransportEndpointGonePeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Init peer state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 InitPeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('init');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function createInitPeerState () {
+ // Get new instance
+ $stateInstance = new InitPeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A helper class for maintaining connection statistics, no instance is
+ * required to use this class.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo Find an interface for hub helper
+ *
+ * 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 ConnectionStatisticsHelper extends BaseHubSystem {
+ /**
+ * Statistics array
+ * @TODO Add more protocols to use
+ */
+ private static $connectionStatistics = array(
+ // Statistics for TCP connections
+ 'tcp' => array(
+ // Tried TCP connection attempts
+ 'retry_count' => array(),
+ ),
+ // Statistics for UDP connections
+ 'udp' => array(
+ // Tried UDP connection attempts
+ 'retry_count' => array(),
+ )
+ );
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Checks whether the retry count has reached a configured limit for given
+ * connection.
+ *
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @return $isExhausted Whether the retry count has been reached
+ */
+ public static function isConnectRetryExhausted (ConnectionHelper $helperInstance) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - CALLED!');
+ // Construct config entry
+ $configEntry = $helperInstance->getProtocolName() . '_connect_retry_max';
+
+ // Check it out
+ $isExhausted = (
+ (
+ isset(self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'])
+ ) && (
+ self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'] >= $helperInstance->getConfigInstance()->getConfigEntry($configEntry)
+ )
+ );
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!');
+ return $isExhausted;
+ }
+
+ /**
+ * Increaes connect-retry count for given connection
+ *
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @return void
+ */
+ public static function increaseConnectRetry (ConnectionHelper $helperInstance) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - CALLED!');
+ // Is the counter there
+ if (!isset(self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'])) {
+ // First attempt
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - FIRST!');
+ self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'] = 1;
+ } else {
+ // Next attempt
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!');
+ self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count']++;
+ }
+
+ // Create/update 'last_update' for purging
+ // @TODO last_update is not being used at the moment
+ self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['last_update'] = time();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A class for handling incoming (encoded) raw data with start and end markers.
+ * The "stream" is being verified by its length (if modulo 4 of it is always
+ * zero) and if the "stream" contains all valid characters (the BASE64
+ * "alphabet").
+ *
+ * Since the latest refacturing this class works "handler-less".
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 RawDataInputStream extends BaseStream implements InputStream {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this node class
+ *
+ * @return $streamInstance An instance of this node class
+ */
+ public final static function createRawDataInputStream () {
+ // Get a new instance
+ $streamInstance = new RawDataInputStream();
+
+ // Return the instance
+ return $streamInstance;
+ }
+
+ /**
+ * Streams the data and maybe does something to it
+ *
+ * @param $data The data (string mostly) to "stream"
+ * @return $data The data (string mostly) to "stream"
+ * @todo Do we need to do something more here?
+ * @throws Base64EncodingModuloException If the data's length modulo 4 is not zero
+ * @throws Base64EncodingBadException If the data contains characters which are not in the "alphabet" of BASE64 messages.
+ * @throws MultipleMessageSentException If the sender has sent two messages and both end up here
+ */
+ public function streamData ($data) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RAW-INPUT-STREAM[' . __METHOD__ . ':' . __LINE__ . ': data(' . strlen($data) . ')=' . $data);
+
+ // Do we have start and end marker again?
+ assert($this->ifStartEndMarkersSet($data));
+
+ // Count of start and end markers must be the same
+ assert(substr_count($data, BaseRawDataHandler::STREAM_START_MARKER) == substr_count($data, BaseRawDataHandler::STREAM_END_MARKER));
+
+ // Check if more than two start markers exist and if so, split it.
+ if (substr_count($data, BaseRawDataHandler::STREAM_START_MARKER) > 1) {
+ // Please do it outside this method
+ throw new MultipleMessageSentException(array($this, $data), BaseHubSystem::EXCEPTION_MULTIPLE_MESSAGE_SENT);
+ } // END - if
+
+ // Remove both
+ $data = substr($data, strlen(BaseRawDataHandler::STREAM_START_MARKER), -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER));
+
+ // Can it be validated?
+ if ((strlen($data) % 4) != 0) {
+ // Length modulo 4 must be zero, else it is an invalid Base64 message
+ throw new Base64EncodingModuloException(array($this, $data), BaseHubSystem::EXCEPTION_BASE64_ENCODING_NOT_MODULO_4);
+ } elseif (!$this->isBase64Encoded($data)) {
+ // Is not a valid Base64-encoded message
+ throw new Base64EncodingBadException(array($this, $data), BaseHubSystem::EXCEPTION_BASE64_BAD_ENCODING);
+ } else {
+ // Decode the data with BASE64-encoding
+ $data = base64_decode($data);
+ }
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RAW-INPUT-STREAM: Length of data is now ' . strlen($data) . ' Bytes.');
+
+ // Return it
+ return $data;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A RawDataOutputStream class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 RawDataOutputStream extends BaseStream implements OutputStream {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this node class
+ *
+ * @return $streamInstance An instance of this node class
+ */
+ public final static function createRawDataOutputStream () {
+ // Get a new instance
+ $streamInstance = new RawDataOutputStream();
+
+ // Return the instance
+ return $streamInstance;
+ }
+
+ /**
+ * Streams the data and maybe does something to it
+ *
+ * @param $data The data (string mostly) to "stream"
+ * @return $data The data (string mostly) to "stream"
+ */
+ public function streamData ($data) {
+ /*
+ * Encode the data with BASE64 encoding and put it in a "frame":
+ *
+ * [[S]] - Start marker
+ * [[E]] - End marker
+ */
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RAW-OUTPUT-STREAM[' . __METHOD__ . ':' . __LINE__ . ']: data()=' . strlen($data) . ' - BEFORE!');
+ $data = BaseRawDataHandler::STREAM_START_MARKER . base64_encode($data) . BaseRawDataHandler::STREAM_END_MARKER;
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RAW-OUTPUT-STREAM[' . __METHOD__ . ':' . __LINE__ . ']: data(' . strlen($data) . ')=' . $data);
+
+ // Return it
+ return $data;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? tags class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Tags extends BaseTags implements Tagable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $tagsInstance An instance of a Tagable class
+ */
+ public final static function create???Tags () {
+ // Get new instance
+ $tagsInstance = new ???Tags();
+
+ // Return the prepared instance
+ return $tagsInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Tags class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseTags extends BaseHubSystem implements Registerable {
+ /**
+ * An array with all tags
+ */
+ private $tags = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Setter for whole tags array
+ *
+ * @param $tags A new simple array with tags
+ * @return void
+ */
+ protected final function setTags (array $tags) {
+ $this->tags = $tags;
+ }
+
+ /**
+ * Getter for whole tags array
+ *
+ * @return $tags A new simple array with tags
+ */
+ protected final function getTags () {
+ return $this->tags;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Package tags class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageTags extends BaseTags implements Tagable {
+ // Exception codes
+ const EXCEPTION_INVALID_TAG = 0x160;
+
+ /**
+ * Last found protocol instance
+ */
+ private $lastProtocol = NULL;
+
+ /**
+ * Last found recipient type
+ */
+ private $lastRecipientType = 'invalid';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init the object registry
+ $this->initObjectRegistry();
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $tagsInstance An instance of a Tagable class
+ */
+ public static final function createPackageTags () {
+ // Get new instance
+ $tagsInstance = new PackageTags();
+
+ // Return the prepared instance
+ return $tagsInstance;
+ }
+
+ /**
+ * Loads the XML file (our "object registry") and saves an instance for
+ * faster re-use.
+ *
+ * @return void
+ */
+ private function initObjectRegistry () {
+ // Output debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Initializing object registry - CALLED!');
+
+ // Get the application instance
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Get a XML template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_object_registry_template_class');
+
+ // Set it for later use
+ $this->setTemplateInstance($templateInstance);
+
+ // Read the XML file
+ $this->getTemplateInstance()->loadXmlTemplate();
+
+ // Render the XML content
+ $this->getTemplateInstance()->renderXmlContent();
+
+ // Output debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Initializing object registry - EXIT!');
+ }
+
+ /**
+ * Extracts the tags from given package data
+ *
+ * @param $packageData Raw package data
+ * @return void
+ */
+ private function extractTagsFromPackageData (array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE));
+
+ /*
+ * We take a look at the tags (in most cases only one is needed) so
+ * first we need the content data splitted up into all it's parts.
+ */
+ $contentData = explode(NetworkPackage::PACKAGE_MASK_SEPARATOR, $packageData[NetworkPackage::PACKAGE_DATA_CONTENT]);
+
+ // Get the tags and store them locally
+ $this->setTags(explode(NetworkPackage::PACKAGE_TAGS_SEPARATOR, $contentData[NetworkPackage::INDEX_TAGS]));
+ }
+
+ /**
+ * Verifies all tags by looking them up in an XML file. This method is
+ * the key method to make sure only known objects are being distributed and
+ * shared over the whole hub-network. So if the "tag" (let's better say
+ * object type) isn't found in that XML the package won't be distributed.
+ *
+ * @param $packageData Raw package data
+ * @return void
+ * @throws InvalidTagException If a provided tag from the package data is invalid
+ */
+ private function verifyAllTags (array $packageData) {
+ // Get the registry
+ $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
+
+ // "Walk" over all tags
+ foreach ($this->getTags() as $tag) {
+ // Debug output
+ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Validating tag ' . $tag . ' ...');
+
+ // Get an array from this tag
+ $entry = $objectRegistryInstance->getArrayFromKey(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME, $tag);
+
+ /*
+ * If it is no array or the array is empty or an entry is missing
+ * the entry is invalid.
+ */
+ if ((!is_array($entry)) || (count($entry) == 0) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL])) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]))) {
+ // Invalid entry found
+ throw new InvalidTagException(array($this, $tag), self::EXCEPTION_INVALID_TAG);
+ } // END - if
+
+ // Now save the last discovered protocol/recipient type
+ $this->lastProtocol = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
+ $this->lastRecipientType = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE];
+ } // END - foreach
+ }
+
+ /**
+ * Chooses the right protocol from given package data
+ *
+ * @param $packageData Raw package data
+ * @return $lastProtocol An instance of the last used HandleableProtocol class
+ */
+ public function chooseProtocolFromPackageData (array $packageData) {
+ // Extract the tags
+ $this->extractTagsFromPackageData($packageData);
+
+ // Now we need to verify every single tag
+ $this->verifyAllTags($packageData);
+
+ // Return the last (and only) found protocol (e.g. 'tcp' is very usual)
+ return $this->lastProtocol;
+ }
+
+ /**
+ * Checks whether the given package data is accepted by the listener
+ *
+ * @param $packageData Raw package data
+ * @param $listenerInstance A Listenable instance
+ * @return $accepts Whether it is accepted
+ */
+ public function ifPackageDataIsAcceptedByListener (array $packageData, Listenable $listenerInstance) {
+ // Extract the tags
+ $this->extractTagsFromPackageData($packageData);
+
+ // Now we need to verify every single tag
+ $this->verifyAllTags($packageData);
+
+ // Now simply check it out
+ $accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid'));
+
+ // And return the result
+ return $accepts;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? task for apt-proxy consoles
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Apt-Proxy Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 AptProxy???Task extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createAptProxy???Task () {
+ // Get new instance
+ $taskInstance = new AptProxy???Task();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A proxy listener task for apt-proxy consoles
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Chat 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 AptProxyListenerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createAptProxyListenerTask () {
+ // Get new instance
+ $taskInstance = new AptProxyListenerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? task for chat consoles
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Chat???Task extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createChat???Task () {
+ // Get new instance
+ $taskInstance = new Chat???Task();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A TelnetListener task for chat consoles
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2012 Chat 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 ChatTelnetListenerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createChatTelnetListenerTask () {
+ // Get new instance
+ $taskInstance = new ChatTelnetListenerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A general URL source Task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 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 BaseUrlSourceTask extends BaseTask {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Initializes URL source task (to keep the constructor small)
+ *
+ * @return void
+ */
+ protected function initUrlSourceTask () {
+ // Get source instance
+ $sourceInstance = UrlSourceObjectFactory::createUrlSourceInstance($this);
+
+ // And set it here
+ $this->setUrlSourceInstance($sourceInstance);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Crawler???Task extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawler???Task () {
+ // Get new instance
+ $taskInstance = new Crawler???Task();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A NodeCommunicator task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerNodeCommunicatorTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerNodeCommunicatorTask () {
+ // Get new instance
+ $taskInstance = new CrawlerNodeCommunicatorTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get the communicator instance
+ $communicatorInstance = CommunicatorFactory::createCommunicatorInstance('crawler_node_communicator_class', 'node');
+
+ // Get the current crawler state from registry
+ $stateInstance = Registry::getRegistry()->getInstance('crawler')->getStateInstance();
+
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
+
+ // We can now invoke that state instance and pass our communicator instance for generating some test units
+ $stateInstance->executeState($communicatorInstance);
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A DocumentParser task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerDocumentParserTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerDocumentParserTask () {
+ // Get new instance
+ $taskInstance = new CrawlerDocumentParserTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A MimeSniffer task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerMimeSnifferTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerMimeSnifferTask () {
+ // Get new instance
+ $taskInstance = new CrawlerMimeSnifferTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Ping task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerPingTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerPingTask () {
+ // Get new instance
+ $taskInstance = new CrawlerPingTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A RemoteJobPublisher task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerRemoteJobPublisherTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerRemoteJobPublisherTask () {
+ // Get new instance
+ $taskInstance = new CrawlerRemoteJobPublisherTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? scanner task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Crawler???ScannerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawler???ScannerTask () {
+ // Get new instance
+ $taskInstance = new Crawler???ScannerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Call factory for a scanner instance and execute it
+ ScannerFactory::createScannerInstance($this)->execute();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A UploadedList scanner task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerUploadedListScannerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerUploadedListScannerTask () {
+ // Get new instance
+ $taskInstance = new CrawlerUploadedListScannerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Call factory for a scanner instance and execute it
+ ScannerObjectFactory::createScannerInstance($this)->execute();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A SnippetExtractor task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerSnippetExtractorTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerSnippetExtractorTask () {
+ // Get new instance
+ $taskInstance = new CrawlerSnippetExtractorTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A StructureAnalyzer task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerStructureAnalyzerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerStructureAnalyzerTask () {
+ // Get new instance
+ $taskInstance = new CrawlerStructureAnalyzerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A LocalUrlCrawler task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerLocalUrlCrawlerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerLocalUrlCrawlerTask () {
+ // Get new instance
+ $taskInstance = new CrawlerLocalUrlCrawlerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A RemoteUrlCrawler task for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerRemoteUrlCrawlerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerRemoteUrlCrawlerTask () {
+ // Get new instance
+ $taskInstance = new CrawlerRemoteUrlCrawlerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An URL source task for ??? for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerUrlSource???Task extends BaseUrlSourceTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawler???Task () {
+ // Get new instance
+ $taskInstance = new Crawler???Task();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get source instance
+ $sourceInstance = $this->getUrlSourceInstance();
+
+ // Is it not set?
+ if (is_null($sourceInstance)) {
+ // Initialize it
+ $this->initUrlSourceTask();
+
+ // And re-get it
+ $sourceInstance = $this->getUrlSourceInstance();
+ } // END - if
+
+ // Get the URL source instance and fill the stack with crawl entries
+ $sourceInstance->fillUrlStack();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An URL source task for FoundRss for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerUrlSourceFoundRssTask extends BaseUrlSourceTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerUrlSourceFoundRssTask () {
+ // Get new instance
+ $taskInstance = new CrawlerUrlSourceFoundRssTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get source instance
+ $sourceInstance = $this->getUrlSourceInstance();
+
+ // Is it not set?
+ if (is_null($sourceInstance)) {
+ // Initialize it
+ $this->initUrlSourceTask();
+
+ // And re-get it
+ $sourceInstance = $this->getUrlSourceInstance();
+ } // END - if
+
+ // Get the URL source instance and fill the stack with crawl entries
+ $sourceInstance->fillUrlStack();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An URL source task for LocalStart for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerUrlSourceLocalStartTask extends BaseUrlSourceTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerUrlSourceLocalStartTask () {
+ // Get new instance
+ $taskInstance = new CrawlerUrlSourceLocalStartTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get source instance
+ $sourceInstance = $this->getUrlSourceInstance();
+
+ // Is it not set?
+ if (is_null($sourceInstance)) {
+ // Initialize it
+ $this->initUrlSourceTask();
+
+ // And re-get it
+ $sourceInstance = $this->getUrlSourceInstance();
+ } // END - if
+
+ // Get the URL source instance and fill the stack with crawl entries
+ $sourceInstance->fillUrlStack();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An URL source task for RssStart for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerUrlSourceRssStartTask extends BaseUrlSourceTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerUrlSourceRssStartTask () {
+ // Get new instance
+ $taskInstance = new CrawlerUrlSourceRssStartTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get source instance
+ $sourceInstance = $this->getUrlSourceInstance();
+
+ // Is it not set?
+ if (is_null($sourceInstance)) {
+ // Initialize it
+ $this->initUrlSourceTask();
+
+ // And re-get it
+ $sourceInstance = $this->getUrlSourceInstance();
+ } // END - if
+
+ // Get the URL source instance and fill the stack with crawl entries
+ $sourceInstance->fillUrlStack();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An URL source task for UploadedList for crawlers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Crawler Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 CrawlerUrlSourceUploadedListTask extends BaseUrlSourceTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCrawlerUrlSourceUploadedListTask () {
+ // Get new instance
+ $taskInstance = new CrawlerUrlSourceUploadedListTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get source instance
+ $sourceInstance = $this->getUrlSourceInstance();
+
+ // Is it not set?
+ if (is_null($sourceInstance)) {
+ // Initialize it
+ $this->initUrlSourceTask();
+
+ // And re-get it
+ $sourceInstance = $this->getUrlSourceInstance();
+ } // END - if
+
+ // Get the URL source instance and fill the stack with crawl entries
+ $sourceInstance->fillUrlStack();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? task for crunchers
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2012 Cruncher Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Cruncher???Task extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createCruncher???Task () {
+ // Get new instance
+ $taskInstance = new Cruncher???Task();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A KeyProducer task for crunchers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherKeyProducerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public final static function createCruncherKeyProducerTask () {
+ // Get new instance
+ $taskInstance = new CruncherKeyProducerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get the instance
+ $producerInstance = ProducerFactory::createProducerInstance('cruncher_key_producer_class', 'key');
+
+ // Get the current cruncher state from registry
+ $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance();
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
+
+ // We can now invoke that state instance and pass our producer instance for generating some test units
+ $stateInstance->executeState($producerInstance);
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A TestUnitProducer task for crunchers
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherTestUnitProducerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public final static function createCruncherTestUnitProducerTask () {
+ // Get new instance
+ $taskInstance = new CruncherTestUnitProducerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get the producer instance
+ $producerInstance = ProducerFactory::createProducerInstance('cruncher_test_unit_producer_class', 'test_unit');
+
+ // Get the current cruncher state from registry
+ $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance();
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
+
+ // We can now invoke that state instance and pass our producer instance for generating some test units
+ $stateInstance->executeState($producerInstance);
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A WorkUnitFetcher task for crunchers which asks the cruncher to fetch work
+ * units or, if enabled in configuration, work on some test units.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherWorkUnitFetcherTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public final static function createCruncherWorkUnitFetcherTask () {
+ // Get new instance
+ $taskInstance = new CruncherWorkUnitFetcherTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ /*
+ * Get the cruncher instance and call a method which should check if
+ * the in-buffer is going to depleted. If so, new WUs are fetched from
+ * network or (if enabled in config) a random test WU is being
+ * generated. This test WU is for developing only or, if you like, to
+ * test your cruncher loop.
+ *
+ * Please report any bugs you encounter to me.
+ */
+ Registry::getRegistry()->getInstance('cruncher')->doFetchWorkUnits();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A BlockFetcher task for miners which asks the network for new blocks and
+ * starts the "block chain" fetching if no block has been fetched so far.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Miner 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 MinerBlockFetcherTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public final static function createMinerBlockFetcherTask () {
+ // Get new instance
+ $taskInstance = new MinerBlockFetcherTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ /*
+ * Get the miner instance and call a method which should check if
+ * the in-buffer is going to depleted. If so, new WUs are fetched from
+ * network or (if enabled in config) a random test WU is being
+ * generated. This test WU is for developing only or, if you like, to
+ * test your miner loop.
+ *
+ * Please report any bugs you encounter to me.
+ */
+ Registry::getRegistry()->getInstance('miner')->doSearchForBlocks();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A RealGenesisBlockProducer task for miners
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerRealGenesisBlockProducerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public final static function createMinerRealGenesisBlockProducerTask () {
+ // Get new instance
+ $taskInstance = new MinerRealGenesisBlockProducerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get the producer instance
+ $producerInstance = ProducerFactory::createProducerInstance('miner_real_genesis_block_producer_class', 'real_unit');
+
+ // Get the current miner state from registry
+ $stateInstance = Registry::getRegistry()->getInstance('miner')->getStateInstance();
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
+
+ // We can now invoke that state instance and pass our producer instance for generating some test units
+ $stateInstance->executeState($producerInstance);
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A TestGenesisBlockProducer task for miners
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner 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 MinerTestGenesisBlockProducerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public final static function createMinerTestGenesisBlockProducerTask () {
+ // Get new instance
+ $taskInstance = new MinerTestGenesisBlockProducerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get the producer instance
+ $producerInstance = ProducerFactory::createProducerInstance('miner_test_genesis_block_producer_class', 'test_unit');
+
+ // Get the current miner state from registry
+ $stateInstance = Registry::getRegistry()->getInstance('miner')->getStateInstance();
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
+
+ // We can now invoke that state instance and pass our producer instance for generating some test units
+ $stateInstance->executeState($producerInstance);
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? task for miners
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Miner???Task extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createMiner???Task () {
+ // Get new instance
+ $taskInstance = new Miner???Task();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A MinerCommunicator task for miners
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2014 Miner Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 MinerNodeCommunicatorTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createMinerNodeCommunicatorTask () {
+ // Get new instance
+ $taskInstance = new MinerNodeCommunicatorTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get the communicator instance
+ $communicatorInstance = CommunicatorFactory::createCommunicatorInstance('miner_node_communicator_class', 'node');
+
+ // Get the current miner state from it
+ $stateInstance = $communicatorInstance->getStateInstance();
+
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
+
+ // We can now invoke that state instance and pass our communicator instance for generating some test units
+ $stateInstance->executeState($communicatorInstance);
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? task for NetworkPackage
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 NetworkPackage???Task extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNetworkPackage???Task () {
+ // Get new instance
+ $taskInstance = new NetworkPackage???Task();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0%
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A NetworkPackageReader task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NetworkPackageReaderTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public static final function createNetworkPackageReaderTask () {
+ // Get new instance
+ $taskInstance = new NetworkPackageReaderTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Also visit some sub-objects?
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // "Cache" package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Do we have something to handle?
+ if ($packageInstance->isProcessedMessagePending()) {
+ /*
+ * A previously proccessed message is waiting for being
+ * "interpreted". This is done by trying to find a configuration
+ * entry based on 'message_type' element.
+ */
+ $packageInstance->handleProcessedMessage();
+ } elseif ($packageInstance->isNewMessageArrived()) {
+ /*
+ * A fully "decoded" message has been received and added for being
+ * processed. Processing a message should not take long, so mostly
+ * this step involves reading all data through a XML template engine
+ * as "XML variables" from the content (which must be a well-formed
+ * XML) and then pushing it on the next stack "processed messages".
+ */
+ $packageInstance->handleNewlyArrivedMessage();
+ } elseif ($packageInstance->isIncomingRawDataHandled()) {
+ /*
+ * Incoming decoded data has been handled (see below) so it needs to
+ * be assembled back to a "package array". Please see NetworkPackage
+ * for further details (what array elements are required et cetera).
+ */
+ $packageInstance->assembleDecodedDataToPackage();
+ } elseif ($packageInstance->ifMultipleMessagesPending()) {
+ /*
+ * Some raw data contained multiple messages which where now splitted.
+ */
+ $packageInstance->handleMultipleMessages();
+ } elseif ($packageInstance->isNewRawDataPending()) {
+ // Raw, decoded data has been received
+ $packageInstance->handleIncomingDecodedData();
+ } elseif ($packageInstance->ifAssemblerHasPendingDataLeft()) {
+ // Handle any pending data from the package assembler
+ $packageInstance->handleAssemblerPendingData();
+ } // END - if
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A NetworkPackageWriter task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NetworkPackageWriterTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public static final function createNetworkPackageWriterTask () {
+ // Get new instance
+ $taskInstance = new NetworkPackageWriterTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Also visit some sub-objects?
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // "Cache" package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Do we have something to deliver?
+ if ($packageInstance->isEncodedDataPending()) {
+ // Sent encoded (raw) data
+ $packageInstance->sendEncodedData();
+ } elseif ($packageInstance->isPackageWaitingForDelivery()) {
+ // Sent it finally out
+ $packageInstance->sendWaitingPackage();
+ } elseif ($packageInstance->isPackageDeclared()) {
+ // Prepare package for delivery
+ $packageInstance->processDeclaredPackage();
+ } elseif ($packageInstance->isPackageEnqueued()) {
+ // Okay, then deliver (better discover its recipients) this package
+ $packageInstance->declareEnqueuedPackage();
+ }
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Announcement node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeAnnouncementTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public static final function createNodeAnnouncementTask () {
+ // Get new instance
+ $taskInstance = new NodeAnnouncementTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get the node instance and announce us
+ NodeObjectFactory::createNodeInstance()->announceToUpperNodes($this);
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ChunkAssembler node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeChunkAssemblerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodeChunkAssemblerTask () {
+ // Get new instance
+ $taskInstance = new NodeChunkAssemblerTask();
+
+ // Get a chunk handler instance
+ $handlerInstance = ChunkHandlerFactory::createChunkHandlerInstance();
+
+ // And add it to this task instance
+ $taskInstance->setHandlerInstance($handlerInstance);
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Also visit some sub-objects?
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // "Cache" handler instance
+ $handlerInstance = $this->getHandlerInstance();
+
+ // Are there chunks to handle or a final array to assemble?
+ if ($handlerInstance->ifUnassembledChunksAvailable()) {
+ /*
+ * Then do the final steps:
+ *
+ * 1) Sort the final array with ksort(). This will bring the "hash
+ * chunk" up to the last array index and the EOP chunk to the
+ * pre-last array index
+ * 2) Assemble all chunks except two last (see above step)
+ * 3) While so, do the final check on all hashes
+ * 4) If the package is assembled back together, hash it again for
+ * the very final verification.
+ */
+ $handlerInstance->assembleChunksFromFinalArray();
+ } elseif ($handlerInstance->ifUnhandledChunksWithFinalAvailable()) {
+ /*
+ * Then handle them (not all!). This should push all chunks into a
+ * 'final array' for last verification.
+ */
+ $handlerInstance->handleAvailableChunksWithFinal();
+ } elseif ($handlerInstance->ifRawPackageDataIsAvailable()) {
+ /*
+ * The final raw package data is back together again. So feed it
+ * into the next stack for further decoding/processing
+ */
+ $handlerInstance->handledAssembledRawPackageData();
+ }
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? node-task
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Node???Task extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNode???Task () {
+ // Get new instance
+ $taskInstance = new Node???Task();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A PackageDecoder node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodePackageDecoderTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodePackageDecoderTask () {
+ // Get new instance
+ $taskInstance = new NodePackageDecoderTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get a decoder instance
+ $decoderInstance = DecoderFactory::createPackageDecoderInstance();
+
+ // Check if the stacker has some entries left
+ if ($decoderInstance->ifUnhandledRawPackageDataLeft()) {
+ // Then handle it
+ $decoderInstance->handleRawPackageData();
+ } elseif ($decoderInstance->ifDeocedPackagesLeft()) {
+ // Some decoded packages have arrived (for this peer)
+ $decoderInstance->handleDecodedPackage();
+ }
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? node DHT task
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 NodeDht???Task extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodeDht???Task () {
+ // Get new instance
+ $taskInstance = new NodeDht???Task();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A DhtBootstrap node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtBootstrapTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodeDhtBootstrapTask () {
+ // Get new instance
+ $taskInstance = new NodeDhtBootstrapTask();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set the DHT instance here
+ $taskInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Let the DHT class do the work for us
+ $this->getDhtInstance()->bootstrapDht();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A DhtInitialization node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtInitializationTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodeDhtInitializationTask () {
+ // Get new instance
+ $taskInstance = new NodeDhtInitializationTask();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set the DHT instance here
+ $taskInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Intiailize the DHT
+ $this->getDhtInstance()->initDht();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A DhtBootstrap node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtLateBootstrapTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodeDhtLateBootstrapTask () {
+ // Get new instance
+ $taskInstance = new NodeDhtLateBootstrapTask();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set the DHT instance here
+ $taskInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Let the DHT class do the work for us
+ $this->getDhtInstance()->bootstrapDht();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A DhtPublicationCheck node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtPublicationCheckTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodeDhtPublicationCheckTask () {
+ // Get new instance
+ $taskInstance = new NodeDhtPublicationCheckTask();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set the DHT instance here
+ $taskInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo Add more?
+ */
+ public function executeTask () {
+ // Get DHT instance
+ $dhtInstance = $this->getDhtInstance();
+
+ // Has the DHT some unpublished entries?
+ if (($dhtInstance->hasFullyBootstrapped()) && ($dhtInstance->hasUnpublishedEntries())) {
+ // Then initiate publishing them
+ $dhtInstance->initEntryPublication();
+ } // END - if
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A DhtPublication node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtPublicationTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodeDhtPublicationTask () {
+ // Get new instance
+ $taskInstance = new NodeDhtPublicationTask();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set the DHT instance here
+ $taskInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo Add more?
+ */
+ public function executeTask () {
+ // Get DHT instance
+ $dhtInstance = $this->getDhtInstance();
+
+ // Has the DHT some entries pending publication?
+ if ($dhtInstance->hasEntriesPendingPublication()) {
+ // Then publish next entry
+ $dhtInstance->publishEntry();
+ } // END - if
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A DhtQuery node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtQueryTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodeDhtQueryTask () {
+ // Get new instance
+ $taskInstance = new NodeDhtQueryTask();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set the DHT instance here
+ $taskInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo ~5% done
+ */
+ public function executeTask () {
+ // Get DHT instance
+ $dhtInstance = $this->getDhtInstance();
+
+ // Are there "INSERT" node data entries?
+ if ($dhtInstance->ifInsertNodeDataPending()) {
+ // Then insert a single entry
+ $dhtInstance->insertSingleNodeData();
+ } // END - if
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A HubSocketListener task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeSocketListenerTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public static final function createNodeSocketListenerTask () {
+ // Get new instance
+ $taskInstance = new NodeSocketListenerTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Get the node instance from registry
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Visit the pool listener task
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('LISTENER-TASK[' . __METHOD__ . ':' . __LINE__ . ']: Going to visit object ' . $nodeInstance->getListenerPoolInstance()->__toString() . ' ...');
+ $nodeInstance->getListenerPoolInstance()->accept($visitorInstance);
+
+ // Visit this task
+ // @TODO Do we need to visit this task? $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Ping node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodePingTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $listInstance A Listable instance
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public static final function createNodePingTask (Listable $listInstance) {
+ // Get new instance
+ $taskInstance = new NodePingTask();
+
+ // Se the list instance in this task
+ $taskInstance->setListInstance($listInstance);
+
+ // Init ping iterator instance
+ $iteratorInstance = $listInstance->getListIterator();
+
+ // Set it as well
+ $taskInstance->setIteratorInstance($iteratorInstance);
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Also visit some sub-objects?
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A SelfConnect node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeSelfConnectTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public static final function createNodeSelfConnectTask () {
+ // Get new instance
+ $taskInstance = new NodeSelfConnectTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get the node instance and try it
+ NodeObjectFactory::createNodeInstance()->doSelfConnection($this);
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A PackageTagsInit node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodePackageTagsInitTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodePackageTagsInitTask () {
+ // Get new instance
+ $taskInstance = new NodePackageTagsInitTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo Maybe visit some sub-objects
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Get a factory instance and do no more as this loads the object (tags) registry
+ $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A UpdateCheck node-task
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeUpdateCheckTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Taskable/Visitable class
+ */
+ public static final function createNodeUpdateCheckTask () {
+ // Get new instance
+ $taskInstance = new NodeUpdateCheckTask();
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ * @todo 0%
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ $this->partialStub('Unimplemented task.');
+ }
+
+ /**
+ * Shuts down the task
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doShutdown () {
+ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An Announcement template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Some XML nodes must be available for later data extraction
+ */
+ const ANNOUNCEMENT_DATA_SESSION_ID = 'session-id';
+ const ANNOUNCEMENT_DATA_NODE_ID = 'node-id';
+ const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'private-key-hash';
+ const ANNOUNCEMENT_DATA_NODE_STATUS = 'node-status';
+ const ANNOUNCEMENT_DATA_NODE_MODE = 'node-mode';
+ const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'external-address';
+ const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'internal-address';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->setSubNodes(array(
+ 'announcement-data',
+ 'listener',
+ self::ANNOUNCEMENT_DATA_NODE_STATUS,
+ self::ANNOUNCEMENT_DATA_NODE_MODE,
+ self::ANNOUNCEMENT_DATA_NODE_ID,
+ self::ANNOUNCEMENT_DATA_SESSION_ID,
+ self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
+ self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
+ 'object-type-list',
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlAnnouncementTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlAnnouncementTemplateEngine();
+
+ // Init template instance
+ $templateInstance->initXmlTemplateEngine('node', 'announcement');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ /*
+ * Assign the found characters to variable and use the last entry from
+ * stack as the name.
+ */
+ parent::assignVariable($this->getStackInstance()->getNamed('node_announcement'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getMenuCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the announcement
+ *
+ * @return void
+ */
+ protected function startAnnouncement () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', 'announcement');
+ }
+
+ /**
+ * Starts the announcement data
+ *
+ * @return void
+ */
+ protected function startAnnouncementData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', 'announcement-data');
+ }
+
+ /**
+ * Starts the node status
+ *
+ * @return void
+ */
+ protected function startNodeStatus () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
+ }
+
+ /**
+ * Starts the node-mode
+ *
+ * @return void
+ */
+ protected function startNodeMode () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_MODE);
+ }
+
+ /**
+ * Starts the listener
+ *
+ * @return void
+ */
+ protected function startListener () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', 'listener');
+ }
+
+ /**
+ * Starts the session id
+ *
+ * @return void
+ */
+ protected function startSessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
+ }
+
+ /**
+ * Starts the node id
+ *
+ * @return void
+ */
+ protected function startNodeId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_ID);
+ }
+
+ /**
+ * Starts the private key hash
+ *
+ * @return void
+ */
+ protected function startPrivateKeyHash () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
+ }
+
+ /**
+ * Starts the public ip
+ *
+ * @return void
+ */
+ protected function startExternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
+ }
+
+ /**
+ * Starts the private ip
+ *
+ * @return void
+ */
+ protected function startInternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
+ }
+
+ /**
+ * Starts the object type list
+ *
+ * @return void
+ */
+ protected function startObjectTypeList () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', 'object-type-list');
+ }
+
+ /**
+ * Starts the object type
+ *
+ * @return void
+ */
+ protected function startObjectType () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement', 'object-type');
+ }
+
+ /**
+ * Finishes the object type
+ *
+ * @return void
+ */
+ protected function finishObjectType () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the object type list
+ *
+ * @return void
+ */
+ protected function finishObjectTypeList () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the private key hash
+ *
+ * @return void
+ */
+ protected function finishPrivateKeyHash () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the node id
+ *
+ * @return void
+ */
+ protected function finishNodeId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the session id
+ *
+ * @return void
+ */
+ protected function finishSessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the private ip
+ *
+ * @return void
+ */
+ protected function finishInternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the public ip
+ *
+ * @return void
+ */
+ protected function finishExternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the listener
+ *
+ * @return void
+ */
+ protected function finishListener () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the node mode
+ *
+ * @return void
+ */
+ protected function finishNodeMode () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the node status
+ *
+ * @return void
+ */
+ protected function finishNodeStatus () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the announcement data
+ *
+ * @return void
+ */
+ protected function finishAnnouncementData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+
+ /**
+ * Finishes the announcement
+ *
+ * @return void
+ */
+ protected function finishAnnouncement () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An AnnouncementAnswer template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Some XML nodes must be available for later data extraction
+ */
+ const ANNOUNCEMENT_DATA_NODE_ID = 'my-node-id';
+ const ANNOUNCEMENT_DATA_SESSION_ID = 'my-session-id';
+ const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash';
+ const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status';
+ const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address';
+ const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init sub-nodes array
+ $this->setSubNodes(array(
+ // These nodes don't contain any data
+ 'my-data',
+ 'your-data',
+ // Data from *this* node
+ self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
+ self::ANNOUNCEMENT_DATA_NODE_STATUS,
+ self::ANNOUNCEMENT_DATA_NODE_ID,
+ self::ANNOUNCEMENT_DATA_SESSION_ID,
+ self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
+ // Data from other node
+ 'your-external-address',
+ 'your-internal-address',
+ 'your-node-id',
+ 'your-session-id',
+ 'your-private-key-hash',
+ // Answer status (generic field)
+ self::ANSWER_STATUS,
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlAnnouncementAnswerTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
+
+ // Init instance
+ $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ * @todo Find something useful with this!
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ /*
+ * Assign the found characters to variable and use the last entry from
+ * stack as the name.
+ */
+ parent::assignVariable($this->getStackInstance()->getNamed('node_announcement_answer'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getAnnouncementAnswerCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the announcement-answer
+ *
+ * @return void
+ */
+ protected function startAnnouncementAnswer () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
+ }
+
+ /**
+ * Starts the my-data
+ *
+ * @return void
+ */
+ protected function startMyData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', 'my-data');
+ }
+
+ /**
+ * Starts the my-external-address
+ *
+ * @return void
+ */
+ protected function startMyExternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
+ }
+
+ /**
+ * Starts the my-internal-address
+ *
+ * @return void
+ */
+ protected function startMyInternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
+ }
+
+ /**
+ * Starts the my-node-id
+ *
+ * @return void
+ */
+ protected function startMyNodeId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_ID);
+ }
+
+ /**
+ * Starts the my-session-id
+ *
+ * @return void
+ */
+ protected function startMySessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
+ }
+
+ /**
+ * Starts the my-private-key-hash
+ *
+ * @return void
+ */
+ protected function startMyPrivateKeyHash () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
+ }
+
+ /**
+ * Starts the my-status
+ *
+ * @return void
+ */
+ protected function startMyStatus () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
+ }
+
+ /**
+ * Finishes the my-status
+ *
+ * @return void
+ */
+ protected function finishMyStatus () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the my-private-key-hash
+ *
+ * @return void
+ */
+ protected function finishMyPrivateKeyhash () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the my-session-id
+ *
+ * @return void
+ */
+ protected function finishMySessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the my-node-id
+ *
+ * @return void
+ */
+ protected function finishMyNodeId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the my-internal-address
+ *
+ * @return void
+ */
+ protected function finishMyInternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the my-external-address
+ *
+ * @return void
+ */
+ protected function finishMyExternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the my-data
+ *
+ * @return void
+ */
+ protected function finishMyData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Starts the your-data
+ *
+ * @return void
+ */
+ protected function startYourData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-data');
+ }
+
+ /**
+ * Starts the your-external-address
+ *
+ * @return void
+ */
+ protected function startYourExternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-external-address');
+ }
+
+ /**
+ * Starts the your-internal-address
+ *
+ * @return void
+ */
+ protected function startYourInternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-internal-address');
+ }
+
+ /**
+ * Starts the your-session-id
+ *
+ * @return void
+ */
+ protected function startYourSessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-session-id');
+ }
+
+ /**
+ * Starts the your-node-id
+ *
+ * @return void
+ */
+ protected function startYourNodeId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-node-id');
+ }
+
+ /**
+ * Starts the your-private-key-hash
+ *
+ * @return void
+ */
+ protected function startYourPrivateKeyHash () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-private-key-hash');
+ }
+
+ /**
+ * Finishes the your-private-key-hash
+ *
+ * @return void
+ */
+ protected function finishYourPrivateKeyHash () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the your-node-id
+ *
+ * @return void
+ */
+ protected function finishYourNodeId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the your-session-id
+ *
+ * @return void
+ */
+ protected function finishYourSessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the your-internal-address
+ *
+ * @return void
+ */
+ protected function finishYourInternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the your-external-address
+ *
+ * @return void
+ */
+ protected function finishYourExternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the your-data
+ *
+ * @return void
+ */
+ protected function finishYourData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+
+ /**
+ * Finishes the announcement-answer
+ *
+ * @return void
+ */
+ protected function finishAnnouncementAnswer () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_announcement_answer');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An ??? answer template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 Xml???AnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXml???TemplateEngine () {
+ // Get a new instance
+ $templateInstance = new Xml???TemplateEngine();
+
+ // Init template instannce
+ $templateInstance->initXmlTemplateEngine('PREFIX', '!!!');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return false;
+ } // END - if
+
+ // Assign data with matching variable here
+ parent::assignVariable($this->getStackInstance()->getNamed('!!!'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function get???CacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the |||
+ *
+ * @return void
+ */
+ protected function start??? () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('!!!', '|||');
+ }
+
+ /**
+ * Finishes the |||
+ *
+ * @return void
+ */
+ protected function finish??? () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('!!!');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An generic answer template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 BaseXmlAnswerTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Generic 'answer-status' field
+ */
+ const ANSWER_STATUS = 'answer-status';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Starts the answer-status
+ *
+ * @return void
+ */
+ protected function startAnswerStatus () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed($this->getStackerName(), self::ANSWER_STATUS);
+ }
+
+ /**
+ * Finishes the answer-status
+ *
+ * @return void
+ */
+ protected function finishAnswerStatus () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed($this->getStackerName());
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An DhtBootstrapAnswer template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Some XML nodes must be available for later data extraction
+ */
+ const DHT_BOOTSTRAP_DATA_SESSION_ID = 'my-session-id';
+ const DHT_BOOTSTRAP_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash';
+ const DHT_BOOTSTRAP_DATA_NODE_STATUS = 'my-status';
+ const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'my-external-address';
+ const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'my-internal-address';
+ const DHT_BOOTSTRAP_DATA_NODE_LIST = 'dht-nodes-list';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init sub-nodes array
+ $this->setSubNodes(array(
+ // These nodes don't contain any data
+ 'my-data',
+ 'your-data',
+ // Data from *this* node
+ self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
+ self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
+ self::DHT_BOOTSTRAP_DATA_SESSION_ID,
+ // Data from other node
+ 'your-external-address',
+ 'your-internal-address',
+ 'your-session-id',
+ // Answer status (generic field)
+ self::ANSWER_STATUS,
+ // DHT node list
+ self::DHT_BOOTSTRAP_DATA_NODE_LIST,
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlDhtBootstrapAnswerTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlDhtBootstrapAnswerTemplateEngine();
+
+ // Init instance
+ $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap_answer');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ * @todo Find something useful with this!
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ /*
+ * Assign the found characters to variable and use the last entry from
+ * stack as the name.
+ */
+ parent::assignVariable($this->getStackInstance()->getNamed('node_dht_bootstrap_answer'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getDhtBootstrapAnswerCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the dht_bootstrap-answer
+ *
+ * @return void
+ */
+ protected function startDhtBootstrapAnswer () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'dht_bootstrap-answer');
+ }
+
+ /**
+ * Starts the my-data
+ *
+ * @return void
+ */
+ protected function startMyData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'my-data');
+ }
+
+ /**
+ * Starts the my-external-address
+ *
+ * @return void
+ */
+ protected function startMyExternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS);
+ }
+
+ /**
+ * Starts the my-internal-address
+ *
+ * @return void
+ */
+ protected function startMyInternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS);
+ }
+
+ /**
+ * Starts the my-session-id
+ *
+ * @return void
+ */
+ protected function startMySessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
+ }
+
+ /**
+ * Starts the my-private-key-hash
+ *
+ * @return void
+ */
+ protected function startMyPrivateKeyHash () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_PRIVATE_KEY_HASH);
+ }
+
+ /**
+ * Starts the my-status
+ *
+ * @return void
+ */
+ protected function startMyStatus () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
+ }
+
+ /**
+ * Starts the dht-nodes-list
+ *
+ * @return void
+ */
+ protected function startDhtNodesList () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_LIST);
+ }
+
+ /**
+ * Finishes the dht-nodes-list
+ *
+ * @return void
+ */
+ protected function finishDhtNodesList () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-status
+ *
+ * @return void
+ */
+ protected function finishMyStatus () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-private-key-hash
+ *
+ * @return void
+ */
+ protected function finishMyPrivateKeyHash () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-session-id
+ *
+ * @return void
+ */
+ protected function finishMySessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-internal-address
+ *
+ * @return void
+ */
+ protected function finishMyInternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-external-address
+ *
+ * @return void
+ */
+ protected function finishMyExternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the my-data
+ *
+ * @return void
+ */
+ protected function finishMyData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Starts the your-data
+ *
+ * @return void
+ */
+ protected function startYourData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-data');
+ }
+
+ /**
+ * Starts the your-external-address
+ *
+ * @return void
+ */
+ protected function startYourExternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-external-address');
+ }
+
+ /**
+ * Starts the your-internal-address
+ *
+ * @return void
+ */
+ protected function startYourInternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-internal-address');
+ }
+
+ /**
+ * Starts the your-session-id
+ *
+ * @return void
+ */
+ protected function startYourSessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-session-id');
+ }
+
+ /**
+ * Starts the your-private-key-hash
+ *
+ * @return void
+ */
+ protected function startYourPrivateKeyHash () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-private-key-hash');
+ }
+
+ /**
+ * Finishes the your-private-key-hash
+ *
+ * @return void
+ */
+ protected function finishYourPrivateKeyHash () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the your-session-id
+ *
+ * @return void
+ */
+ protected function finishYourSessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the your-internal-address
+ *
+ * @return void
+ */
+ protected function finishYourInternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the your-external-address
+ *
+ * @return void
+ */
+ protected function finishYourExternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the your-data
+ *
+ * @return void
+ */
+ protected function finishYourData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+
+ /**
+ * Finishes the dht_bootstrap-answer
+ *
+ * @return void
+ */
+ protected function finishDhtBootstrapAnswer () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A RequestNodeListAnswer template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlRequestNodeListAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
+ // Constants for array elements
+ const REQUEST_DATA_SESSION_ID = 'session-id';
+ const REQUEST_DATA_NODE_LIST = 'node-list';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init sub-nodes array
+ $this->setSubNodes(array(
+ self::REQUEST_DATA_SESSION_ID,
+ self::REQUEST_DATA_NODE_LIST,
+ // Answer status (generic field)
+ self::ANSWER_STATUS,
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlRequestNodeListAnswerTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlRequestNodeListAnswerTemplateEngine();
+
+ // Init instance
+ $templateInstance->initXmlTemplateEngine('node', 'request_node_list_answer');
+
+ // Get a template instance for list entries (as they are dynamic)
+ $entriesInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_entries_template_class');
+
+ // Set it here
+ $templateInstance->setTemplateInstance($entriesInstance);
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ * @todo Find something useful with this!
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ /*
+ * Assign the found characters to variable and use the last entry from
+ * stack as the name.
+ */
+ parent::assignVariable($this->getStackInstance()->getNamed('node_request_node_list_answer'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getRequestNodeListAnswerCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the 'request-node-list-answer'
+ *
+ * @return void
+ */
+ protected function startRequestNodeListAnswer () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_request_node_list_answer', 'request-node-list-answer');
+ }
+
+ /**
+ * Starts the session-id
+ *
+ * @return void
+ */
+ protected function startSessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_request_node_list_answer', self::REQUEST_DATA_SESSION_ID);
+ }
+
+ /**
+ * Starts the node-list
+ *
+ * @return void
+ */
+ protected function startNodeList () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_request_node_list_answer', self::REQUEST_DATA_NODE_LIST);
+ }
+
+ /**
+ * Finishes the node-list
+ *
+ * @return void
+ */
+ protected function finishNodeList () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_request_node_list_answer');
+ }
+
+ /**
+ * Finishes the session-id
+ *
+ * @return void
+ */
+ protected function finishSessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_request_node_list_answer');
+ }
+
+ /**
+ * Finishes the 'request-node-list-answer'
+ *
+ * @return void
+ */
+ protected function finishRequestNodeListAnswer () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_request_node_list_answer');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An ??? template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 Xml???TemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXml???TemplateEngine () {
+ // Get a new instance
+ $templateInstance = new Xml???TemplateEngine();
+
+ // Init template instannce
+ $templateInstance->initXmlTemplateEngine('PREFIX', '!!!');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return false;
+ } // END - if
+
+ // Assign data with matching variable here
+ parent::assignVariable($this->getStackInstance()->getNamed('!!!'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function get???CacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the |||
+ *
+ * @return void
+ */
+ protected function start??? () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('!!!', '|||');
+ }
+
+ /**
+ * Finishes the |||
+ *
+ * @return void
+ */
+ protected function finish??? () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('!!!');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A generic XML template engine class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 BaseXmlTemplateEngine extends BaseTemplateEngine {
+ /**
+ * Main nodes in the XML tree
+ */
+ private $mainNodes = array();
+
+ /**
+ * Sub nodes in the XML tree
+ */
+ private $subNodes = array();
+
+ /**
+ * Current main node
+ */
+ private $curr = array();
+
+ /**
+ * XML template type
+ */
+ private $xmlTemplateType = 'xml';
+
+ /**
+ * Type prefix
+ */
+ private $typePrefix = 'xml';
+
+ /**
+ * Name of stacker
+ */
+ private $stackerName = '';
+
+ /**
+ * Content from dependency
+ */
+ protected $dependencyContent = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Does a generic initialization of the template engine
+ *
+ * @param $typePrefix Type prefix
+ * @param $xmlTemplateType Type of XML template
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ protected function initXmlTemplateEngine ($typePrefix, $xmlTemplateType) {
+ // Get template instance
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Determine base path
+ $templateBasePath = $this->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
+
+ // Is the base path valid?
+ if (empty($templateBasePath)) {
+ // Base path is empty
+ throw new BasePathIsEmptyException($this, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } elseif (!is_string($templateBasePath)) {
+ // Is not a string
+ throw new InvalidBasePathStringException(array($this, $templateBasePath), self::EXCEPTION_INVALID_STRING);
+ } elseif (!is_dir($templateBasePath)) {
+ // Is not a path
+ throw new BasePathIsNoDirectoryException(array($this, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
+ } elseif (!is_readable($templateBasePath)) {
+ // Is not readable
+ throw new BasePathReadProtectedException(array($this, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
+ }
+
+ // Set the base path
+ $this->setTemplateBasePath($templateBasePath);
+
+ // Set template extensions
+ $this->setRawTemplateExtension($this->getConfigInstance()->getConfigEntry('raw_template_extension'));
+ $this->setCodeTemplateExtension($this->getConfigInstance()->getConfigEntry($typePrefix . '_message_template_extension'));
+
+ // Absolute output path for compiled templates
+ $this->setCompileOutputPath($this->getConfigInstance()->getConfigEntry('base_path') . $this->getConfigInstance()->getConfigEntry('compile_output_path'));
+
+ // Init a variable stacker
+ $stackInstance = ObjectFactory::createObjectByConfiguredName($typePrefix . '_' . $xmlTemplateType . '_stacker_class');
+
+ // Set name
+ $this->stackerName = $typePrefix . '_' . $xmlTemplateType;
+
+ // Init stacker
+ $stackInstance->initStack($this->stackerName);
+
+ // Set it
+ $this->setStackInstance($stackInstance);
+
+ // Set XML template type and prefix
+ $this->xmlTemplateType = $xmlTemplateType;
+ $this->typePrefix = $typePrefix;
+
+ // Set it in main nodes
+ array_push($this->mainNodes, str_replace('_', '-', $xmlTemplateType));
+ }
+
+ /**
+ * Load a specified XML template into the engine
+ *
+ * @param $templateName Optional name of template
+ * @return void
+ */
+ public function loadXmlTemplate ($templateName = '') {
+ // Is the template name empty?
+ if (empty($templateName)) {
+ // Set generic template name
+ $templateName = $this->typePrefix . '_' . $this->xmlTemplateType . '_template_type';
+ } // END - if
+
+ // Set template type
+ $this->setTemplateType($this->getConfigInstance()->getConfigEntry($templateName));
+
+ // Load the special template
+ $this->loadTemplate($this->xmlTemplateType);
+ }
+
+ /**
+ * Getter for current main node
+ *
+ * @return $currMainNode Current main node
+ */
+ public final function getCurrMainNode () {
+ return $this->curr['main_node'];
+ }
+
+ /**
+ * Setter for current main node
+ *
+ * @param $element Element name to set as current main node
+ * @return $currMainNode Current main node
+ */
+ private final function setCurrMainNode ($element) {
+ $this->curr['main_node'] = (string) $element;
+ }
+
+ /**
+ * Getter for main node array
+ *
+ * @return $mainNodes Array with valid main node names
+ */
+ public final function getMainNodes () {
+ return $this->mainNodes;
+ }
+
+ /**
+ * Getter for stacker name
+ *
+ * @return $stackerName Name of stacker of this class
+ */
+ protected final function getStackerName () {
+ return $this->stackerName;
+ }
+
+ /**
+ * Setter for sub node array
+ *
+ * @param $subNodes Array with valid sub node names
+ * @return void
+ */
+ public final function setSubNodes (array $subNodes) {
+ $this->subNodes = $subNodes;
+ }
+
+ /**
+ * Getter for sub node array
+ *
+ * @return $subNodes Array with valid sub node names
+ */
+ public final function getSubNodes () {
+ return $this->subNodes;
+ }
+
+ /**
+ * Read XML variables by calling readVariable() with 'general' as
+ * variable stack.
+ *
+ * @param $key Key to read from
+ * @return $value Value from variable
+ */
+ public function readXmlData ($key) {
+ // Read the variable
+ $value = parent::readVariable($key, 'general');
+
+ // Is this null?
+ if (is_null($value)) {
+ // Bah, needs fixing.
+ $this->debugInstance('key=' . $key . ' returns NULL');
+ } // END - if
+
+ // Return value
+ return $value;
+ }
+
+ /**
+ * Handles the template dependency for given XML node
+ *
+ * @param $node The XML node we should load a dependency template
+ * @param $templateDependency A template to load to satisfy dependencies
+ * @return void
+ */
+ protected function handleTemplateDependency ($node, $templateDependency) {
+ // Check that the XML node is not empty
+ assert(!empty($node));
+
+ // Is the template dependency set?
+ if ((!empty($templateDependency)) && (!isset($this->dependencyContent[$node]))) {
+ // Get a temporay template instance
+ $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance($this->typePrefix . '_' . self::convertDashesToUnderscores($node) . '_' . $this->xmlTemplateType . '_template_class');
+
+ // Then load it
+ $templateInstance->loadXmlTemplate($templateDependency);
+
+ // Parse the XML content
+ $templateInstance->renderXmlContent();
+
+ // Save the parsed raw content in our dependency array
+ $this->dependencyContent[$node] = $templateInstance->getRawTemplateData();
+ } // END - if
+ }
+
+ /**
+ * Handles the start element of an XML resource
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $element The element we shall handle
+ * @param $attributes All attributes
+ * @return void
+ * @throws InvalidXmlNodeException If an unknown/invalid XML node name was found
+ */
+ public final function startElement ($resource, $element, array $attributes) {
+ // Initial method name which will never be called...
+ $methodName = 'init' . self::convertToClassName($this->xmlTemplateType);
+
+ // Make the element name lower-case
+ $element = strtolower($element);
+
+ // Is the element a main node?
+ //* DEBUG: */ echo "START: >".$element."<<br />\n";
+ if (in_array($element, $this->getMainNodes())) {
+ // Okay, main node found!
+ $methodName = 'start' . self::convertToClassName($element);
+
+ // Set it
+ $this->setCurrMainNode($element);
+ } elseif (in_array($element, $this->getSubNodes())) {
+ // Sub node found
+ $methodName = 'start' . self::convertToClassName($element);
+ } else {
+ // Invalid node name found
+ throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
+ }
+
+ // Call method
+ call_user_func_array(array($this, $methodName), $attributes);
+ }
+
+ /**
+ * Ends the main or sub node by sending out the gathered data
+ *
+ * @param $resource An XML resource pointer (currently ignored)
+ * @param $nodeName Name of the node we want to finish
+ * @return void
+ * @throws XmlNodeMismatchException If current main node mismatches the closing one
+ */
+ public final function finishElement ($resource, $nodeName) {
+ // Make all lower-case
+ $nodeName = strtolower($nodeName);
+
+ // Does this match with current main node?
+ //* DEBUG: */ echo "END: >".$nodeName."<<br />\n";
+ if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
+ // Did not match!
+ throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH);
+ } // END - if
+
+ // Construct method name
+ $methodName = 'finish' . self::convertToClassName($nodeName);
+
+ // Call the corresponding method
+ //* DEBUG: */ echo "call: ".$methodName."<br />\n";
+ call_user_func_array(array($this, $methodName), array());
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An SelfConnect template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlSelfConnectTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Data nodes
+ */
+ const SELF_CONNECT_DATA_NODE_ID = 'node-id';
+ const SELF_CONNECT_DATA_SESSION_ID = 'session-id';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->setSubNodes(array(
+ 'self-connect-data',
+ self::SELF_CONNECT_DATA_NODE_ID,
+ self::SELF_CONNECT_DATA_SESSION_ID
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlSelfConnectTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlSelfConnectTemplateEngine();
+
+ // Init template instance
+ $templateInstance->initXmlTemplateEngine('node', 'self_connect');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ * @todo Find something useful with this!
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ /*
+ * Assign the found characters to variable and use the last entry from
+ * stack as the name
+ */
+ parent::assignVariable($this->getStackInstance()->getNamed('node_self_connect'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getMenuCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the self_connect
+ *
+ * @return void
+ */
+ protected function startSelfConnect () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_self_connect', 'self-connect');
+ }
+
+ /**
+ * Starts the self_connect data
+ *
+ * @return void
+ */
+ protected function startSelfConnectData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_self_connect', 'self-connect-data');
+ }
+
+ /**
+ * Starts the node id
+ *
+ * @return void
+ */
+ protected function startNodeId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_self_connect', self::SELF_CONNECT_DATA_NODE_ID);
+ }
+
+ /**
+ * Starts the session id
+ *
+ * @return void
+ */
+ protected function startSessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_self_connect', self::SELF_CONNECT_DATA_SESSION_ID);
+ }
+
+ /**
+ * Finishes the session id
+ *
+ * @return void
+ */
+ protected function finishSessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_self_connect');
+ }
+
+ /**
+ * Finishes the node id
+ *
+ * @return void
+ */
+ protected function finishNodeId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_self_connect');
+ }
+
+ /**
+ * Finishes the self_connect data
+ *
+ * @return void
+ */
+ protected function finishSelfConnectData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_self_connect');
+ }
+
+ /**
+ * Finishes the self_connect
+ *
+ * @return void
+ */
+ protected function finishSelfConnect () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_self_connect');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An Bootstrap template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlDhtBootstrapTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Some XML nodes must be available for later data extraction
+ */
+ const DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA = 'dht-bootstrap-data';
+ const DHT_BOOTSTRAP_DATA_SESSION_ID = 'session-id';
+ const DHT_BOOTSTRAP_DATA_NODE_STATUS = 'node-status';
+ const DHT_BOOTSTRAP_DATA_NODE_MODE = 'node-mode';
+ const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'external-address';
+ const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'internal-address';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->setSubNodes(array(
+ self::DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA,
+ 'listener',
+ self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
+ self::DHT_BOOTSTRAP_DATA_NODE_MODE,
+ self::DHT_BOOTSTRAP_DATA_SESSION_ID,
+ self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlDhtBootstrapTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlDhtBootstrapTemplateEngine();
+
+ // Init template instance
+ $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ /*
+ * Assign the found characters to variable and use the last entry from
+ * stack as the name.
+ */
+ parent::assignVariable($this->getStackInstance()->getNamed('dht_bootstrap'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getMenuCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the dht bootstrap
+ *
+ * @return void
+ */
+ protected function startDhtBootstrap () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_bootstrap', 'dht-bootstrap');
+ }
+
+ /**
+ * Starts the dht bootstrap data
+ *
+ * @return void
+ */
+ protected function startDhtBootstrapData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA);
+ }
+
+ /**
+ * Starts the node status
+ *
+ * @return void
+ */
+ protected function startNodeStatus () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
+ }
+
+ /**
+ * Starts the node-mode
+ *
+ * @return void
+ */
+ protected function startNodeMode () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_MODE);
+ }
+
+ /**
+ * Starts the listener
+ *
+ * @return void
+ */
+ protected function startListener () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_bootstrap', 'listener');
+ }
+
+ /**
+ * Starts the public ip
+ *
+ * @return void
+ */
+ protected function startExternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS);
+ }
+
+ /**
+ * Starts the private ip
+ *
+ * @return void
+ */
+ protected function startInternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS);
+ }
+
+ /**
+ * Starts the session id
+ *
+ * @return void
+ */
+ protected function startSessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
+ }
+
+ /**
+ * Finishes the session id
+ *
+ * @return void
+ */
+ protected function finishSessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_bootstrap');
+ }
+
+ /**
+ * Finishes the private ip
+ *
+ * @return void
+ */
+ protected function finishInternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_bootstrap');
+ }
+
+ /**
+ * Finishes the public ip
+ *
+ * @return void
+ */
+ protected function finishExternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_bootstrap');
+ }
+
+ /**
+ * Finishes the listener
+ *
+ * @return void
+ */
+ protected function finishListener () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_bootstrap');
+ }
+
+ /**
+ * Finishes the node mode
+ *
+ * @return void
+ */
+ protected function finishNodeMode () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_bootstrap');
+ }
+
+ /**
+ * Finishes the node status
+ *
+ * @return void
+ */
+ protected function finishNodeStatus () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_bootstrap');
+ }
+
+ /**
+ * Finishes the dht bootstrap data
+ *
+ * @return void
+ */
+ protected function finishDhtBootstrapData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_bootstrap');
+ }
+
+ /**
+ * Finishes the dht bootstrap
+ *
+ * @return void
+ */
+ protected function finishDhtBootstrap () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_bootstrap');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An RequestNodeListEntry template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlRequestNodeListEntryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlRequestNodeListEntryTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlRequestNodeListEntryTemplateEngine();
+
+ // Init template instannce
+ $templateInstance->initXmlTemplateEngine('node', 'request_node_list_entry');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ * @todo Find something useful with this!
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ // Assign data with matching variable here
+ parent::assignVariable($this->getStackInstance()->getNamed('node_request_node_list_entry'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getRequestNodeListEntryCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the request-node-list-entry
+ *
+ * @return void
+ */
+ protected function startRequestNodeListEntry () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_request_node_list_entry', 'request-node-list-entry');
+ }
+
+ /**
+ * Finishes the request-node-list-entry
+ *
+ * @return void
+ */
+ protected function finishRequestNodeListEntry () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_request_node_list_entry');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An ObjectRegistry template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ // Constants
+ const OBJECT_TYPE_DATA_NAME = 'object-name';
+ const OBJECT_TYPE_DATA_RECIPIENT_LIMITATION = 'object-recipient-limitation';
+ const OBJECT_TYPE_DATA_MAX_SPREAD = 'object-max-spread';
+ const OBJECT_TYPE_DATA_PROTOCOL = 'object-protocol';
+ const OBJECT_TYPE_DATA_RECIPIENT_TYPE = 'object-recipient-type';
+
+ /**
+ * Instance for the object registry
+ */
+ private $objectRegistryInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init object type registry instance
+ $this->objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
+
+ // Init sub nodes
+ $this->setSubNodes(array(
+ 'object-list',
+ 'object-list-entry',
+ self::OBJECT_TYPE_DATA_NAME,
+ self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION,
+ self::OBJECT_TYPE_DATA_MAX_SPREAD,
+ self::OBJECT_TYPE_DATA_PROTOCOL,
+ self::OBJECT_TYPE_DATA_RECIPIENT_TYPE
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlObjectRegistryTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlObjectRegistryTemplateEngine();
+
+ // Init template instance
+ $templateInstance->initXmlTemplateEngine('node', 'object_registry');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ * @todo Find something useful with this!
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ // Get current XML node name as an array index
+ $nodeName = $this->getStackInstance()->getNamed('node_object_registry');
+
+ // Is the node name self::OBJECT_TYPE_DATA_NAME?
+ if ($nodeName == self::OBJECT_TYPE_DATA_NAME) {
+ // Output debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Adding object type ' . $characters . ' to registry.');
+ } // END - if
+
+ // Add it to the registry
+ $this->objectRegistryInstance->addEntry($nodeName, $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getObjectRegistryCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the object-registry
+ *
+ * @return void
+ */
+ protected function startObjectRegistry () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_object_registry', 'object-registry');
+ }
+
+ /**
+ * Starts the object-list
+ *
+ * @param $objectCount Count of all objects
+ * @return void
+ * @todo Handle $objectCount
+ */
+ protected function startObjectList ($objectCount) {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_object_registry', 'object-list');
+ }
+
+ /**
+ * Starts the object-list-entry
+ *
+ * @return void
+ */
+ protected function startObjectListEntry () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_object_registry', 'object-list-entry');
+ }
+
+ /**
+ * Starts the object-name
+ *
+ * @return void
+ */
+ protected function startObjectName () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_NAME);
+ }
+
+ /**
+ * Starts the object-recipient-limitation
+ *
+ * @return void
+ */
+ protected function startObjectRecipientLimitation () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION);
+ }
+
+ /**
+ * Starts the object-max-spread
+ *
+ * @return void
+ */
+ protected function startObjectMaxSpread () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_MAX_SPREAD);
+ }
+
+ /**
+ * Starts the object-protocol
+ *
+ * @return void
+ */
+ protected function startObjectProtocol () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_PROTOCOL);
+ }
+
+ /**
+ * Starts the object-recipient-type
+ *
+ * @return void
+ */
+ protected function startObjectRecipientType () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_TYPE);
+ }
+
+ /**
+ * Finishes the object-recipient-type
+ *
+ * @return void
+ */
+ protected function finishObjectRecipientType () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_object_registry');
+ }
+
+ /**
+ * Finishes the object-protocol
+ *
+ * @return void
+ */
+ protected function finishObjectProtocol () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_object_registry');
+ }
+
+ /**
+ * Finishes the object-max-spread
+ *
+ * @return void
+ */
+ protected function finishObjectMaxSpread () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_object_registry');
+ }
+
+ /**
+ * Finishes the object-recipient-limitation
+ *
+ * @return void
+ */
+ protected function finishObjectRecipientLimitation () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_object_registry');
+ }
+
+ /**
+ * Finishes the object-name
+ *
+ * @return void
+ */
+ protected function finishObjectName () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_object_registry');
+ }
+
+ /**
+ * Finishes the object-list-entry
+ *
+ * @return void
+ */
+ protected function finishObjectListEntry () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_object_registry');
+ }
+
+ /**
+ * Finishes the object-list
+ *
+ * @return void
+ */
+ protected function finishObjectList () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_object_registry');
+ }
+
+ /**
+ * Finishes the object-registry
+ *
+ * @return void
+ */
+ protected function finishObjectRegistry () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_object_registry');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An TestUnit template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlCruncherTestUnitTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init sub nodes
+ $this->setSubNodes(array(
+ 'meta-data',
+ 'global-project-identifier',
+ 'test-unit-created',
+ 'cipher',
+ 'cipher-function',
+ 'cipher-name',
+ 'unprocessed-data',
+ 'encrypted-message',
+ 'cruncher-key-list',
+ 'cruncher-key',
+ 'key-id',
+ 'key-value'
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlCruncherTestUnitTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlCruncherTestUnitTemplateEngine();
+
+ // Init template instance
+ $templateInstance->initXmlTemplateEngine('cruncher', 'test_unit');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ // Assign the found characters to variable and use the last entry from
+ // stack as the name
+ parent::assignVariable($this->getStackInstance()->getNamed('cruncher_test_unit'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getCruncherTestUnitCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the test-unit
+ *
+ * @return void
+ */
+ protected function startTestUnit () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cruncher-test-unit');
+ }
+
+ /**
+ * Starts the meta-data
+ *
+ * @return void
+ */
+ protected function startMetaData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'meta-data');
+ }
+
+ /**
+ * Starts the global-project-identifier
+ *
+ * @return void
+ */
+ protected function startGlobalProjectIdentifier () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'global-project-identifier');
+ }
+
+ /**
+ * Finishes the global-project-identifier
+ *
+ * @return void
+ */
+ protected function finishGlobalProjectIdentifier () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Starts the test-unit-created
+ *
+ * @return void
+ */
+ protected function startTestUnitCreated () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'test-unit-created');
+ }
+
+ /**
+ * Finishes the test-unit-created
+ *
+ * @return void
+ */
+ protected function finishTestUnitCreated () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Starts the cipher
+ *
+ * @return void
+ */
+ protected function startCipher () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cipher');
+ }
+
+ /**
+ * Starts the cipher-function
+ *
+ * @return void
+ */
+ protected function startCipherFunction () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cipher-function');
+ }
+
+ /**
+ * Finishes the cipher-function
+ *
+ * @return void
+ */
+ protected function finishCipherFunction () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Starts the cipher-name
+ *
+ * @return void
+ */
+ protected function startCipherName () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cipher-name');
+ }
+
+ /**
+ * Finishes the cipher-name
+ *
+ * @return void
+ */
+ protected function finishCipherName () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Finishes the cipher
+ *
+ * @return void
+ */
+ protected function finishCipher () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Finishes the meta-data
+ *
+ * @return void
+ */
+ protected function finishMetaData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Starts the unprocessed-data
+ *
+ * @return void
+ */
+ protected function startUnprocessedData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'unprocessed-data');
+ }
+
+ /**
+ * Starts the encrypted-message
+ *
+ * @return void
+ */
+ protected function startEncryptedMessage () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'encrypted-message');
+ }
+
+ /**
+ * Finishes the encrypted-message
+ *
+ * @return void
+ */
+ protected function finishEncryptedMessage () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Starts the cruncher-key-list
+ *
+ * @param $keyCount Count of keys in this test unit
+ * @return void
+ * @todo Handle $keyCount
+ */
+ protected function startCruncherKeyList ($keyCount) {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cruncher-key-list');
+ }
+
+ /**
+ * Starts the cruncher-key
+ *
+ * @return void
+ */
+ protected function startCruncherKey () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cruncher-key');
+ }
+
+ /**
+ * Starts the key-id
+ *
+ * @return void
+ */
+ protected function startKeyId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'key-id');
+ }
+
+ /**
+ * Finishes the key-id
+ *
+ * @return void
+ */
+ protected function finishKeyId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Starts the key-value
+ *
+ * @return void
+ */
+ protected function startKeyValue () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('cruncher_test_unit', 'key-value');
+ }
+
+ /**
+ * Finishes the key-value
+ *
+ * @return void
+ */
+ protected function finishKeyValue () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Finishes the cruncher-key
+ *
+ * @return void
+ */
+ protected function finishCruncherKey () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Finishes the cruncher-key-list
+ *
+ * @return void
+ */
+ protected function finishCruncherKeyList () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Finishes the unprocessed-data
+ *
+ * @return void
+ */
+ protected function finishUnprocessedData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+
+ /**
+ * Finishes the test-unit
+ *
+ * @return void
+ */
+ protected function finishTestUnit () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('cruncher_test_unit');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An PublishEntry template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlDhtPublishEntryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ /**
+ * Some XML nodes must be available for later data extraction
+ */
+ const PUBLISH_DATA_NODE_ID = 'node-id';
+ const PUBLISH_DATA_SESSION_ID = 'session-id';
+ const PUBLISH_DATA_NODE_STATUS = 'node-status';
+ const PUBLISH_DATA_NODE_MODE = 'node-mode';
+ const PUBLISH_DATA_EXTERNAL_ADDRESS = 'external-address';
+ const PUBLISH_DATA_PRIVATE_KEY_HASH = 'private-key-hash';
+ const PUBLISH_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->setSubNodes(array(
+ 'publish-data',
+ 'listener',
+ self::PUBLISH_DATA_NODE_STATUS,
+ self::PUBLISH_DATA_NODE_MODE,
+ self::PUBLISH_DATA_PRIVATE_KEY_HASH,
+ self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES,
+ self::PUBLISH_DATA_NODE_ID,
+ self::PUBLISH_DATA_SESSION_ID,
+ self::PUBLISH_DATA_EXTERNAL_ADDRESS,
+ 'object-type-list',
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlDhtPublishEntryTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlDhtPublishEntryTemplateEngine();
+
+ // Init template instance
+ $templateInstance->initXmlTemplateEngine('node', 'dht_publish');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ /*
+ * Assign the found characters to variable and use the last entry from
+ * stack as the name.
+ */
+ parent::assignVariable($this->getStackInstance()->getNamed('dht_publish'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getMenuCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the publish
+ *
+ * @return void
+ */
+ protected function startPublish () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', 'publish');
+ }
+
+ /**
+ * Starts the publish data
+ *
+ * @return void
+ */
+ protected function startPublishData () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', 'publish-data');
+ }
+
+ /**
+ * Starts the node status
+ *
+ * @return void
+ */
+ protected function startNodeStatus () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_STATUS);
+ }
+
+ /**
+ * Starts the node-mode
+ *
+ * @return void
+ */
+ protected function startNodeMode () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_MODE);
+ }
+
+ /**
+ * Starts the listener
+ *
+ * @return void
+ */
+ protected function startListener () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', 'listener');
+ }
+
+ /**
+ * Starts accepted object types
+ *
+ * @return void
+ */
+ protected function startAcceptedObjectTypes () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES);
+ }
+
+ /**
+ * Starts hash from private key
+ *
+ * @return void
+ */
+ protected function startPrivateKeyHash () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_PRIVATE_KEY_HASH);
+ }
+
+ /**
+ * Starts the node id
+ *
+ * @return void
+ */
+ protected function startNodeId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_ID);
+ }
+
+ /**
+ * Starts the session id
+ *
+ * @return void
+ */
+ protected function startSessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_SESSION_ID);
+ }
+
+ /**
+ * Starts the public ip
+ *
+ * @return void
+ */
+ protected function startExternalAddress () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_EXTERNAL_ADDRESS);
+ }
+
+ /**
+ * Starts the object type list
+ *
+ * @return void
+ */
+ protected function startObjectTypeList () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', 'object-type-list');
+ }
+
+ /**
+ * Starts the object type
+ *
+ * @return void
+ */
+ protected function startObjectType () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('dht_publish', 'object-type');
+ }
+
+ /**
+ * Finishes the object type
+ *
+ * @return void
+ */
+ protected function finishObjectType () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes the object type list
+ *
+ * @return void
+ */
+ protected function finishObjectTypeList () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes the session id
+ *
+ * @return void
+ */
+ protected function finishSessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes the node id
+ *
+ * @return void
+ */
+ protected function finishNodeId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes the public ip
+ *
+ * @return void
+ */
+ protected function finishExternalAddress () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes hash from private key
+ *
+ * @return void
+ */
+ protected function finishPrivateKeyHash () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes accepted object types
+ *
+ * @return void
+ */
+ protected function finishAcceptedObjectTypes () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes the listener
+ *
+ * @return void
+ */
+ protected function finishListener () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes the node mode
+ *
+ * @return void
+ */
+ protected function finishNodeMode () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes the node status
+ *
+ * @return void
+ */
+ protected function finishNodeStatus () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes the publish data
+ *
+ * @return void
+ */
+ protected function finishPublishData () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+
+ /**
+ * Finishes the publish
+ *
+ * @return void
+ */
+ protected function finishPublish () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('dht_publish');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An ??? template engine class for XML templates
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ * @todo This template engine does not make use of setTemplateType()
+ *
+ * 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 XmlRequestNodeListTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
+ // Constants for array elements
+ const REQUEST_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types';
+ const REQUEST_DATA_SESSION_ID = 'session-id';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init sub nodes
+ $this->setSubNodes(array(
+ self::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
+ self::REQUEST_DATA_SESSION_ID,
+ ));
+ }
+
+ /**
+ * Creates an instance of the class TemplateEngine and prepares it for usage
+ *
+ * @return $templateInstance An instance of TemplateEngine
+ * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
+ * @throws InvalidBasePathStringException If $templateBasePath is no string
+ * @throws BasePathIsNoDirectoryException If $templateBasePath is no
+ * directory or not found
+ * @throws BasePathReadProtectedException If $templateBasePath is
+ * read-protected
+ */
+ public static final function createXmlRequestNodeListTemplateEngine () {
+ // Get a new instance
+ $templateInstance = new XmlRequestNodeListTemplateEngine();
+
+ // Init template instance
+ $templateInstance->initXmlTemplateEngine('node', 'request_node_list');
+
+ // Return the prepared instance
+ return $templateInstance;
+ }
+
+ /**
+ * Currently not used
+ *
+ * @param $resource XML parser resource (currently ignored)
+ * @param $characters Characters to handle
+ * @return void
+ * @todo Find something useful with this!
+ */
+ public function characterHandler ($resource, $characters) {
+ // Trim all spaces away
+ $characters = trim($characters);
+
+ // Is this string empty?
+ if (empty($characters)) {
+ // Then skip it silently
+ return;
+ } // END - if
+
+ // Assign data with matching variable here
+ parent::assignVariable($this->getStackInstance()->getNamed('node_request_node_list'), $characters);
+ }
+
+ /**
+ * Getter for cache file (FQFN)
+ *
+ * @return $fqfn Full-qualified file name of the menu cache
+ */
+ public function getRequestNodeListCacheFqfn () {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Starts the node-request-node-list
+ *
+ * @return void
+ */
+ protected function startRequestNodeList () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_request_node_list', 'node-request-node-list');
+ }
+
+ /**
+ * Starts the accepted-object-types
+ *
+ * @return void
+ */
+ protected function startAcceptedObjectTypes () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_request_node_list', self::REQUEST_DATA_ACCEPTED_OBJECT_TYPES);
+ }
+
+ /**
+ * Starts the session-id
+ *
+ * @return void
+ */
+ protected function startSessionId () {
+ // Push the node name on the stacker
+ $this->getStackInstance()->pushNamed('node_request_node_list', self::REQUEST_DATA_SESSION_ID);
+ }
+
+ /**
+ * Finishes the session-id
+ *
+ * @return void
+ */
+ protected function finishSessionId () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_request_node_list');
+ }
+
+ /**
+ * Finishes the accepted-object-types
+ *
+ * @return void
+ */
+ protected function finishAcceptedObjectTypes () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_request_node_list');
+ }
+
+ /**
+ * Finishes the node-request-node-list
+ *
+ * @return void
+ */
+ protected function finishRequestNodeList () {
+ // Pop the last entry
+ $this->getStackInstance()->popNamed('node_request_node_list');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * This class contains static helper functions for our hub
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubTools extends BaseHubSystem {
+ // Constants for exceptions
+ const EXCEPTION_SESSION_ID_IS_INVALID = 0x200;
+ const EXCEPTION_HOSTNAME_NOT_FOUND = 0x201;
+
+ /**
+ * Cache for session ids
+ */
+ private $sessionIdCache = array();
+
+ /**
+ * Length for session id (should be 32+salt_length
+ */
+ private $sessionIdLength = 0;
+
+ /**
+ * Self instance
+ */
+ private static $selfInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set it here
+ $this->setDhtInstance($dhtInstance);
+
+ // Init salt length
+ $this->sessionIdLength = 32 + $this->getConfigInstance()->getConfigEntry('salt_length');
+ }
+
+ /**
+ * Singleton getter for self instance
+ *
+ * @retuen $selfInstance An instance of this class
+ */
+ public static final function getSelfInstance () {
+ // Is the instance set
+ if (is_null(self::$selfInstance)) {
+ // Then set it
+ self::$selfInstance = new HubTools();
+ } // END - if
+
+ // Return own instance
+ return self::$selfInstance;
+ }
+
+ /**
+ * Getter for session id length
+ *
+ * @return $sessionIdLength Length of session ids
+ */
+ protected final function getSessionIdLength () {
+ return $this->sessionIdLength;
+ }
+
+ /**
+ * Resolves a session id into an instance of a LocateableNode class. The opposite method
+ * is resolveSessionIdByUniversalNodeLocator()
+ *
+ * @param $sessionId A valid session id
+ * @return $recipientUniversalNodeLocator Recipient as Universal Node Locator
+ */
+ protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
+ // Init variable
+ $recipientUniversalNodeLocator = 'invalid://invalid:invalid';
+
+ // And ask it for Universal Node Locator by given session id
+ $recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId);
+ //* DEBUG-DIE: */ die(__METHOD__ . ': UNFINISHED: recipient[' . gettype($recipient) . ']=' . print_r($recipient, TRUE) . ',sessionId=' . $sessionId . PHP_EOL);
+
+ // Is the recipient valid?
+ if (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS])) {
+ // Then use this
+ $recipientUniversalNodeLocator = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS];
+ } else {
+ // Get the instance, this might throw a NPE
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Is the session id the same?
+ if ($nodeInstance->getSessionId() == $sessionId) {
+ // Then get an instance of a LocateableNode class from it, assume TCP by default
+ $recipientUniversalNodeLocator = self::determineOwnExternalAddress() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
+ } // END - if
+ }
+
+ // Return result
+ return $recipientUniversalNodeLocator;
+ }
+
+ /**
+ * Resolves a session id into a node id by asking local DHT.
+ *
+ * @param $sessionId Session id
+ * @return $nodeId Node id
+ */
+ public static function resolveNodeIdBySessionId ($sessionId) {
+ // Get an own instance
+ $selfInstance = self::getSelfInstance();
+
+ // And ask it for session id by given Universal Node Locator
+ $nodeData = $selfInstance->getDhtInstance()->findNodeLocalBySessionId($sessionId);
+
+ // Make sure the node id is there
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ', nodeData[' . gettype($nodeData) . ']=' . print_r($nodeData, TRUE));
+ assert(isset($nodeData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_NODE_ID]));
+
+ // Return it
+ return $nodeData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_NODE_ID];
+ }
+
+ /**
+ * Resolves a Universal Node Locator into a session id. The "opposite" method
+ * is resolveUniversalNodeLocatorBySessionId().
+ *
+ * @param $unlInstance Universal Node Locator
+ * @return $sessionId Valid session id
+ */
+ public static function resolveSessionIdByUniversalNodeLocator (LocateableNode $unlInstance) {
+ // Get an own instance
+ $selfInstance = self::getSelfInstance();
+
+ // And ask it for session id by given Universal Node Locator
+ $recipient = $selfInstance->getDhtInstance()->findNodeByUniversalNodeLocator($unlInstance);
+ die(__METHOD__.':recipient='.print_r($recipient, TRUE));
+
+ // Return result
+ return $sessionId;
+ }
+
+ /**
+ * Resolves given session id into an instance of a LocateableNode class, if Universal Node Locator is set, it won't be translated
+ *
+ * @param $address Session id or Universal Node Locator
+ * @return $recipient Recipient as Universal Node Locator
+ * @throws InvalidSessionIdException If the provided session id is invalid (and no Universal Node Locator)
+ * @throws NoValidHostnameException If the provided hostname cannot be resolved into an IP address
+ */
+ public static function resolveSessionId ($address) {
+ // Get an own instance
+ $selfInstance = self::getSelfInstance();
+
+ // Default is direct Universal Node Locator
+ $recipient = $address;
+
+ // Does it match a direct Universal Node Locator? (hint: see www.regexlib.com for the regular expression)
+ if (preg_match('/([a-z0-9]{3,10})\/\/:([a-z0-9\.]{5,})/', $address)) {
+ // @TODO ((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})
+ // Direct Universal Node Locator found
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Direct Universal Node Locator ' . $address . ' detected.');
+ } elseif (isset($selfInstance->sessionIdCache[$address])) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using entry from sessionIdCache[] array.');
+
+ // Found in cache!
+ $recipient = $selfInstance->sessionIdCache[$address];
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: sessionIdCache[' . $address . ']=' . $recipient);
+ } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $address)) {
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using internal session id resolver.');
+
+ // Resolve session id into an instance of a LocateableNode class
+ $recipient = $selfInstance->resolveUniversalNodeLocatorBySessionId($address);
+
+ // Debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Session id ' . $address . ' resolved to ' . $recipient);
+ } else {
+ // Invalid session id/UNL
+ throw new InvalidSessionIdException($address, self::EXCEPTION_SESSION_ID_IS_INVALID);
+ }
+
+ // Return it
+ return $recipient;
+ }
+
+ /**
+ * Determine UNL or 'external_address' if set
+ *
+ * @return $unl The determined external UNL of this node
+ */
+ public static function determineOwnExternalAddress () {
+ // Is the external_address config entry set?
+ if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address') != '') {
+ // Use it as external address
+ $unl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address');
+ } else {
+ // Determine own external address by connecting to my (coder) server at 188.138.90.169
+ $unl = self::determineExternalUniversalNodeLocator();
+ }
+
+ // Return it
+ return $unl;
+ }
+
+ /**
+ * Determine UNL or 'internal_address' if set
+ *
+ * @return $unl The determined internal UNL of this node
+ */
+ public static function determineOwnInternalAddress () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is the internal_address config entry set?
+ if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Calling self::determineOwnExternalAddress() as allow_publish_internal_address=N is set ...');
+
+ // Not allowed to publish internal address, so use external
+ $unl = self::determineOwnExternalAddress();
+ } elseif (FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address') != '') {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Getting config entry internal_address ...');
+
+ // Use it as internal address
+ $unl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address');
+ } else {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Calling self::determineInternalUniversalNodeLocator() ...');
+
+ // Determine own internal address
+ $unl = self::determineInternalUniversalNodeLocator();
+ }
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ' - EXIT!');
+
+ // Return it
+ return $unl;
+ }
+
+ /**
+ * Determines the UNL (Universal Node Locator) for the internal address
+ *
+ * @return $internalUnl Internal UNL
+ */
+ public static function determineInternalUniversalNodeLocator () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is there cache? (This shortens a lot calls)
+ if (!isset($GLOBALS[__METHOD__])) {
+ // Determine UNL based on this node:
+ // 1) Get discovery class
+ $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
+
+ // 2) "Determine" it
+ $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('internal');
+
+ // Make sure it is valid
+ // @TODO Find a better validation than empty()
+ assert(!empty($GLOBALS[__METHOD__]));
+ } // END - if
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
+ return $GLOBALS[__METHOD__];
+ }
+
+ /**
+ * Determines the UNL (Universal Node Locator) for the external address
+ *
+ * @return $externalUnl External UNL
+ */
+ public static function determineExternalUniversalNodeLocator () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is there cache? (This shortens a lot calls)
+ if (!isset($GLOBALS[__METHOD__])) {
+ // Determine UNL based on this node:
+ // 1) Get discovery class
+ $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
+
+ // 2) "Determine" it
+ $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('external');
+
+ // Make sure it is valid
+ // @TODO Find a better validation than empty()
+ assert(!empty($GLOBALS[__METHOD__]));
+ } // END - if
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
+ return $GLOBALS[__METHOD__];
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A UniversalNodeLocator
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 UniversalNodeLocator extends BaseFrameworkSystem implements LocateableNode {
+ //------- UNL parts -------
+ // Protocol
+ const UNL_PART_PROTOCOL = 'protocol';
+ // Address
+ const UNL_PART_ADDRESS = 'address';
+ // Extra part
+ const UNL_PART_EXTRA = 'extra';
+ // Port (if any)
+ const UNL_PART_PORT = 'port';
+
+ /**
+ * UNL data array
+ */
+ private $unlData = array();
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
+ * @return $unlInstance An instance of a LocateableNode class
+ */
+ public final static function createUniversalNodeLocator (array $current = array()) {
+ // Get new instance
+ $unlInstance = new UniversalNodeLocator();
+
+ // Init instance
+ $unlInstance->initUniversalNodeLocator($current);
+
+ // Return the prepared instance
+ return $unlInstance;
+ }
+
+ /**
+ * Initializes the UNL instance by givena array. If an entry is found, it
+ * will be copied, otherwise the entry is set empty.
+ *
+ * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
+ * @return void
+ */
+ private function initUniversalNodeLocator (array $current = array()) {
+ // Init UNL array
+ $this->unlData = array();
+
+ // Copy all found entries
+ foreach (array(
+ NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID,
+ NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID,
+ NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH,
+ NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE,
+ NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL,
+ NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) {
+ // Init entry
+ $this->unlData[$key] = NULL;
+
+ // Is the key found?
+ if (isset($current[$key])) {
+ // The copy the entry
+ $this->unlData[$key] = $current[$key];
+ } // END - if
+ } // END - foreach
+ }
+
+ /**
+ * Getter for UNL data array
+ *
+ * @return $unlData An array with UNL data
+ */
+ public final function getUnlData () {
+ return $this->unlData;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? visitor
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 ???Visitor extends BaseVisitor implements PoolVisitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set visitor mode
+ $this->setVisitorMode('???');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public final static function create???Visitor () {
+ // Get new instance
+ $visitorInstance = new ???Visitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+
+ /**
+ * Visits the given pool instance
+ *
+ * @param $poolInstance A Poolable instance
+ * @return void
+ * @todo 0%
+ */
+ public function visitPool (Poolable $poolInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? handler visitor
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Handler???Visitor extends BaseVisitor implements PoolVisitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set visitor mode
+ $this->setVisitorMode('handler');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public final static function createHandler???Visitor () {
+ // Get new instance
+ $visitorInstance = new Handler???Visitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+
+ /**
+ * Visits the given pool instance
+ *
+ * @param $poolInstance A Poolable instance
+ * @return void
+ * @todo 0%
+ */
+ public function visitPool (Poolable $poolInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A RawDataMonitor visitor
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 RawDataPoolMonitorVisitor extends BaseVisitor implements PoolVisitor, ListenerVisitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set visitor mode
+ $this->setVisitorMode('monitor');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $receiverInstance An instance of a Receivable class
+ * @return $visitorInstance An instance of a Visitorable class
+ */
+ public final static function createRawDataPoolMonitorVisitor () {
+ // Get new instance
+ $visitorInstance = new RawDataPoolMonitorVisitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+
+ /**
+ * Visits the given pool instance
+ *
+ * @param $poolInstance A Poolable instance
+ * @return void
+ */
+ public function visitPool (Poolable $poolInstance) {
+ // A pool doesn't normally have any raw data waiting
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: poolInstance=' . $poolInstance->__toString() . ' - CALLED!');
+ }
+
+ /**
+ * Visits the given listener instance
+ *
+ * @param $listenerInstance A Listenable instance
+ * @return void
+ */
+ public function visitListener (Listenable $listenerInstance) {
+ /*
+ * The listener itself cannot distinguish between node and client
+ * traffic. This is why we don't call its monitorIncomingRawData()
+ * method.
+ */
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: listenerInstance=' . $listenerInstance->__toString() . ' - CALLED!');
+ }
+
+ /**
+ * Visits the given decorator instance
+ *
+ * @param $decoratorInstance A decorator instance
+ * @return void
+ */
+ public function visitDecorator (BaseDecorator $decoratorInstance) {
+ // Do monitor here
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - CALLED!');
+ $decoratorInstance->monitorIncomingRawData();
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - FINISH');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? shutdown visitor
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub; Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.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 Shutdown???Visitor extends BaseVisitor implements PoolVisitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set visitor mode
+ $this->setVisitorMode('shutdown');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public final static function createShutdown???Visitor () {
+ // Get new instance
+ $visitorInstance = new Shutdown???Visitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+
+ /**
+ * Visits the given pool instance
+ *
+ * @param $poolInstance A Poolable instance
+ * @return void
+ * @todo 0%
+ */
+ public function visitPool (Poolable $poolInstance) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ListenerPool shutdown visitor
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ShutdownListenerPoolVisitor extends BaseVisitor implements PoolVisitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set visitor mode
+ $this->setVisitorMode('shutdown');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public static final function createShutdownListenerPoolVisitor () {
+ // Get new instance
+ $visitorInstance = new ShutdownListenerPoolVisitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+
+ /**
+ * Visits the given pool instance
+ *
+ * @param $poolInstance A Poolable instance
+ * @return void
+ */
+ public function visitPool (Poolable $poolInstance) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $poolInstance->__toString() . ' - CALLED!');
+
+ // Pre-shutdown the pool
+ $poolInstance->preShutdown();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $poolInstance->__toString() . ' - EXIT!');
+ }
+
+ /**
+ * Visits the given decorator instance
+ *
+ * @param $decoratorInstance A Listenable decorator instance
+ * @return void
+ */
+ public function visitDecorator (Listenable $decoratorInstance) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $decoratorInstance->__toString() . ' - CALLED!');
+
+ // Pre-shutdown the pool
+ $decoratorInstance->doShutdown();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $decoratorInstance->__toString() . ' - EXIT!');
+ }
+
+ /**
+ * Visits the given listener instance
+ *
+ * @param $listenerInstance A Listenable class instance
+ * @return void
+ */
+ public function visitListener (Listenable $listenerInstance) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $listenerInstance->__toString() . ' - CALLED!');
+
+ // Pre-shutdown the pool
+ $listenerInstance->doShutdown();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $listenerInstance->__toString() . ' - EXIT!');
+ }
+}
+
+//
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A HalfShutdownSocket visitor
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HalfShutdownSocketVisitor extends BaseVisitor implements Visitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set visitor mode
+ $this->setVisitorMode('socket');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public static final function createHalfShutdownSocketVisitor () {
+ // Get new instance
+ $visitorInstance = new HalfShutdownSocketVisitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+
+ /**
+ * "Visit" method to do the actual request. Here we want to shutdown the
+ * attached socket.
+ *
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @return void
+ */
+ public function visitConnectionHelper (ConnectionHelper $helperInstance) {
+ // Do we have reached the retry count?
+ if (ConnectionStatisticsHelper::isConnectRetryExhausted($helperInstance)) {
+ // Also visit the network package to clear any out-going packages
+ NetworkPackageFactory::createNetworkPackageInstance()->accept($this);
+
+ // Still shutdown the visitor (look in visitNetworkPackage() for details)
+ $helperInstance->doShutdown();
+ } else {
+ // We can still move on and retry the connection attempt
+ ConnectionStatisticsHelper::increaseConnectRetry($helperInstance);
+ }
+ }
+
+ /**
+ * "Visit" method to do the actual request. This method does remove the last
+ * failed package from the stack because all retries are fully exhausted
+ * (see visitConnectionHelper() for the logic).
+ *
+ * @param $packageInstance An instance of a Deliverable class
+ * @return void
+ */
+ public function visitNetworkPackage (Deliverable $packageInstance) {
+ // Just call it back
+ $packageInstance->removeFirstFailedPackage();
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ShutdownSocket visitor
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ShutdownSocketVisitor extends BaseVisitor implements Visitor {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set visitor mode
+ $this->setVisitorMode('socket');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $visitorInstance An instance a Visitorable class
+ */
+ public static final function createShutdownSocketVisitor () {
+ // Get new instance
+ $visitorInstance = new ShutdownSocketVisitor();
+
+ // Return the prepared instance
+ return $visitorInstance;
+ }
+
+ /**
+ * "Visit" method to do the actual request. Here we want to shutdown the
+ * attached socket.
+ *
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @return void
+ */
+ public function visitConnectionHelper (ConnectionHelper $helperInstance) {
+ // Do we have reached the retry count?
+ if (ConnectionStatisticsHelper::isConnectRetryExhausted($helperInstance)) {
+ // Also visit the network package to clear any out-going packages
+ NetworkPackageFactory::createNetworkPackageInstance()->accept($this);
+
+ // Shutdown the connection
+ $helperInstance->doShutdown();
+ } else {
+ // We can still move on and retry the connection attempt
+ ConnectionStatisticsHelper::increaseConnectRetry($helperInstance);
+ }
+ }
+
+ /**
+ * "Visit" method to do the actual request. Here we want to "partly shutdown"
+ * the network package instance to clear all stacks.
+ *
+ * @param $packageInstance An instance of a Deliverable class
+ * @return void
+ */
+ public function visitNetworkPackage (Deliverable $packageInstance) {
+ // Just call it back
+ $packageInstance->clearAllStacks();
+ }
+
+ /**
+ * "Visit" the assembler instance. This shall clear any pending data
+ *
+ * @param $assemblerInstance An instance of a Assembler class
+ * @return void
+ */
+ public function visitAssembler (Assembler $assemblerInstance) {
+ // Clear pending data
+ $assemblerInstance->clearPendingData();
+ }
+}
+
+// [EOF]
+?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A node ??? apt-proxy
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Apt-Proxy Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Node???AptProxy extends BaseNodeAptProxy implements AptProxyter {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $proxyInstance An instance of a AptProxyter class
- */
- public final static function createNode???AptProxy () {
- // Get new instance
- $proxyInstance = new Node???AptProxy();
-
- // Return the prepared instance
- return $proxyInstance;
- }
-
- /**
- * Method to "bootstrap" the apt-proxy. This step does also apply provided
- * command-line arguments stored in the request instance. You should now
- * get it from calling $this->getRequestInstance().
- *
- * @return void
- */
- public function doBootstrapping () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Add some apt-proxy-specific filters
- *
- * @param $controllerInstance An object of a Controller instance
- * @param $responseInstance An object of a Responseable instance
- * @return void
- */
- public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general NodeAptProxy class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 BaseNodeAptProxy extends BaseHubSystem {
- /**
- * Whether this apt-proxy is active
- */
- private $isActive = FALSE;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Enables/disables the apt-proxy (just sets a flag)
- *
- * @param $version Version number of this apt-proxy
- * @return void
- */
- public final function enableIsActive ($isActive = TRUE) {
- $this->isActive = (bool) $isActive;
- }
-
- /**
- * Determines whether the apt-proxy is active
- *
- * @return $isActive Whether the apt-proxy is active
- */
- public final function isActive () {
- return $this->isActive;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A node console apt-proxy
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 NodeConsoleAptProxy extends BaseNodeAptProxy implements AptProxy, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $proxyInstance An instance of a AptProxy class
- */
- public final static function createNodeConsoleAptProxy () {
- // Get new instance
- $proxyInstance = new NodeConsoleAptProxy();
-
- // Return the prepared instance
- return $proxyInstance;
- }
-
- /**
- * Method to "bootstrap" the apt-proxy. This step does also apply provided
- * command-line arguments stored in the request instance. You should now
- * get it from calling $this->getRequestInstance().
- *
- * @return void
- */
- public function doBootstrapping () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- // Get the app instance (for shortening our code)
- $app = $this->getApplicationInstance();
-
- // Output all lines
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - An apt-proxy connection helper');
- self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2012 Apt-Proxy Developer Team');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
- self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
- self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- }
-
- /**
- * Add some apt-proxy-specific filters
- *
- * @param $controllerInstance An object of a Controller instance
- * @param $responseInstance An object of a Responseable instance
- * @return void
- */
- public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? block class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Block extends BaseBlock implements === {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $blockInstance An instance of a === class
- */
- public final static function create???Block () {
- // Get new instance
- $blockInstance = new ???Block();
-
- // Return the prepared instance
- return $blockInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general Block class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 BaseBlock extends BaseHubSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Hash block class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 HashBlock extends BaseBlock implements Minable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $blockInstance An instance of a Minable class
- */
- public final static function createHashBlock () {
- // Get new instance
- $blockInstance = new HashBlock();
-
- // Return the prepared instance
- return $blockInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A filter chain for processing network packages (or better messages)
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageFilterChain extends FilterChain {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $chainInstance An instance of this class
- */
- public static final function createPackageFilterChain () {
- // Get a new instance
- $chainInstance = new PackageFilterChain();
-
- // Return the prepared instance
- return $chainInstance;
- }
-
- /**
- * Processes the given raw message content through all filters
- *
- * @param $messageData Raw message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @todo This may be slow if a message with a lot tags arrived
- */
- public function processMessage (array $messageData, Receivable $packageInstance) {
- // Get all filters and "run" them
- foreach ($this->getFilters() as $filterInstance) {
- // Try to process it
- try {
- $filterInstance->processMessage($messageData, $packageInstance);
- } catch (FilterChainException $e) {
- // This exception can be thrown to just skip any further processing
- self::createDebugInstance(__CLASS__)->debugOutput('Failed to execute lase filter ' . $filterInstance->__toString() . ': ' . $e->getMessage());
- break;
- }
- } // END - foreach
- }
-
- /**
- * Post-processes the stacked message. Do not call popNamed() as then no
- * other class can process the message.
- *
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function postProcessMessage (Receivable $packageInstance) {
- // Get all filters and "run" them
- foreach ($this->getPostFilters() as $filterInstance) {
- // Try to process it
- try {
- $filterInstance->postProcessMessage($packageInstance);
- } catch (FilterChainException $e) {
- // This exception can be thrown to just skip any further processing
- self::createDebugInstance(__CLASS__)->debugOutput('Failed to execute lase filter ' . $filterInstance->__toString() . ': ' . $e->getMessage());
- break;
- }
- } // END - foreach
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A node ??? chat
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Node???Chat extends BaseNodeChat implements Chatter {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $chatInstance An instance of a Chatter class
- */
- public final static function createNode???Chat () {
- // Get new instance
- $chatInstance = new Node???Chat();
-
- // Return the prepared instance
- return $chatInstance;
- }
-
- /**
- * Method to "bootstrap" the chatter. This step does also apply provided
- * command-line arguments stored in the request instance. You should now
- * get it from calling $this->getRequestInstance().
- *
- * @return void
- */
- public function doBootstrapping () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Add some chatter-specific filters
- *
- * @param $controllerInstance An object of a Controller instance
- * @param $responseInstance An object of a Responseable instance
- * @return void
- */
- public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general NodeChat class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 BaseNodeChat extends BaseHubSystem {
- /**
- * Whether this Chatter is active
- */
- private $isActive = FALSE;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Enables/disables the chatter (just sets a flag)
- *
- * @param $version Version number of this chatter
- * @return void
- */
- public final function enableIsActive ($isActive = TRUE) {
- $this->isActive = (bool) $isActive;
- }
-
- /**
- * Determines whether the chatter is active
- *
- * @return $isActive Whether the chatter is active
- */
- public final function isActive () {
- return $this->isActive;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A node console chat
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 NodeConsoleChat extends BaseNodeChat implements Chatter, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $chatInstance An instance of a Chatter class
- */
- public final static function createNodeConsoleChat () {
- // Get new instance
- $chatInstance = new NodeConsoleChat();
-
- // Return the prepared instance
- return $chatInstance;
- }
-
- /**
- * Method to "bootstrap" the chatter. This step does also apply provided
- * command-line arguments stored in the request instance. You should now
- * get it from calling $this->getRequestInstance().
- *
- * @return void
- */
- public function doBootstrapping () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- // Get the app instance (for shortening our code)
- $app = $this->getApplicationInstance();
-
- // Output all lines
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - A telnet connection helper');
- self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2012 Chat Developer Team');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
- self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
- self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- }
-
- /**
- * Add some chatter-specific filters
- *
- * @param $controllerInstance An object of a Controller instance
- * @param $responseInstance An object of a Responseable instance
- * @return void
- */
- public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ???
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ??? extends BaseFrameworkSystem implements === {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $!!!Instance An instance of a === class
- */
- public final static function create??? () {
- // Get new instance
- $!!!Instance = new ???();
-
- // Return the prepared instance
- return $!!!Instance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general ??? class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Base??? extends BaseHubSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general hub system class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubSystem extends BaseFrameworkSystem {
- // Exception codes
- const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x900;
- const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x901;
- const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0x902;
- const EXCEPTION_INVALID_CONNECTION_TYPE = 0x903;
- const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED = 0x904;
- const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4 = 0x905;
- const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0x906;
- const EXCEPTION_REQUEST_NOT_ACCEPTED = 0x907;
- const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED = 0x908;
- const EXCEPTION_MULTIPLE_MESSAGE_SENT = 0x909;
- const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED = 0x90a;
- const EXCEPTION_INVALID_UNL = 0x90b;
-
- // Message status codes
- const MESSAGE_STATUS_CODE_OKAY = 'OKAY';
-
- /**
- * Separator for all bootstrap node entries
- */
- const BOOTSTRAP_NODES_SEPARATOR = ';';
-
- /**
- * An instance of a node
- */
- private $nodeInstance = NULL;
-
- /**
- * A network package handler instance
- */
- private $packageInstance = NULL;
-
- /**
- * A Receivable instance
- */
- private $receiverInstance = NULL;
-
- /**
- * Listener pool instance
- */
- private $listenerPoolInstance = NULL;
-
- /**
- * Fragmenter instance
- */
- private $fragmenterInstance = NULL;
-
- /**
- * Assembler instance
- */
- private $assemblerInstance = NULL;
-
- /**
- * Info instance
- */
- private $infoInstance = NULL;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Setter for network package handler instance
- *
- * @param $packageInstance The network package instance we shall set
- * @return void
- */
- protected final function setPackageInstance (Deliverable $packageInstance) {
- $this->packageInstance = $packageInstance;
- }
-
- /**
- * Getter for network package handler instance
- *
- * @return $packageInstance The network package handler instance we shall set
- */
- protected final function getPackageInstance () {
- return $this->packageInstance;
- }
-
- /**
- * Setter for receiver instance
- *
- * @param $receiverInstance A Receivable instance we shall set
- * @return void
- */
- protected final function setReceiverInstance (Receivable $receiverInstance) {
- $this->receiverInstance = $receiverInstance;
- }
-
- /**
- * Getter for receiver instance
- *
- * @return $receiverInstance A Receivable instance we shall get
- */
- protected final function getReceiverInstance () {
- return $this->receiverInstance;
- }
-
- /**
- * Setter for listener pool instance
- *
- * @param $listenerPoolInstance The new listener pool instance
- * @return void
- */
- protected final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
- $this->listenerPoolInstance = $listenerPoolInstance;
- }
-
- /**
- * Getter for listener pool instance
- *
- * @return $listenerPoolInstance Our current listener pool instance
- */
- public final function getListenerPoolInstance () {
- return $this->listenerPoolInstance;
- }
-
- /**
- * Setter for fragmenter instance
- *
- * @param $fragmenterInstance A Fragmentable instance
- * @return void
- */
- protected final function setFragmenterInstance (Fragmentable $fragmenterInstance) {
- $this->fragmenterInstance = $fragmenterInstance;
- }
-
- /**
- * Getter for fragmenter instance
- *
- * @return $fragmenterInstance A Fragmentable instance
- */
- protected final function getFragmenterInstance () {
- return $this->fragmenterInstance;
- }
-
- /**
- * Setter for assembler instance
- *
- * @param $assemblerInstance An instance of an Assembler class
- * @return void
- */
- protected final function setAssemblerInstance (Assembler $assemblerInstance) {
- $this->assemblerInstance = $assemblerInstance;
- }
-
- /**
- * Getter for assembler instance
- *
- * @return $assemblerInstance An instance of an Assembler class
- */
- protected final function getAssemblerInstance () {
- return $this->assemblerInstance;
- }
-
- /**
- * Setter for info instance
- *
- * @param $infoInstance A ShareableInfo instance
- * @return void
- */
- protected final function setInfoInstance (ShareableInfo $infoInstance) {
- $this->infoInstance = $infoInstance;
- }
-
- /**
- * Getter for info instance
- *
- * @return $infoInstance An instance of a ShareableInfo class
- */
- public final function getInfoInstance () {
- return $this->infoInstance;
- }
-
- /**
- * Setter for node id
- *
- * @param $nodeId The new node id
- * @return void
- */
- protected final function setNodeId ($nodeId) {
- // Set it config now
- $this->getConfigInstance()->setConfigEntry('node_id', (string) $nodeId);
- }
-
- /**
- * Getter for node id
- *
- * @return $nodeId Current node id
- */
- public final function getNodeId () {
- // Get it from config
- return $this->getConfigInstance()->getConfigEntry('node_id');
- }
-
- /**
- * Setter for private key
- *
- * @param $privateKey The new private key
- * @return void
- */
- protected final function setPrivateKey ($privateKey) {
- // Set it config now
- $this->getConfigInstance()->setConfigEntry('private_key', (string) $privateKey);
- }
-
- /**
- * Getter for private key
- *
- * @return $privateKey Current private key
- */
- public final function getPrivateKey () {
- // Get it from config
- return $this->getConfigInstance()->getConfigEntry('private_key');
- }
-
- /**
- * Setter for private key hash
- *
- * @param $privateKeyHash The new private key hash
- * @return void
- */
- protected final function setPrivateKeyHash ($privateKeyHash) {
- // Set it config now
- $this->getConfigInstance()->setConfigEntry('private_key_hash', (string) $privateKeyHash);
- }
-
- /**
- * Getter for private key hash
- *
- * @return $privateKeyHash Current private key hash
- */
- public final function getPrivateKeyHash () {
- // Get it from config
- return $this->getConfigInstance()->getConfigEntry('private_key_hash');
- }
-
- /**
- * Setter for session id
- *
- * @param $sessionId The new session id
- * @return void
- */
- protected final function setSessionId ($sessionId) {
- $this->getConfigInstance()->setConfigEntry('session_id', (string) $sessionId);
- }
-
- /**
- * Getter for session id
- *
- * @return $sessionId Current session id
- */
- public final function getSessionId () {
- return $this->getConfigInstance()->getConfigEntry('session_id');
- }
-
- /**
- * Constructs a callable method name from given socket error code. If the
- * method is not found, a generic one is used.
- *
- * @param $errorCode Error code from socket_last_error()
- * @return $handlerName Call-back method name for the error handler
- * @throws UnsupportedSocketErrorHandlerException If the error handler is not implemented
- */
- protected function getSocketErrorHandlerFromCode ($errorCode) {
- // Create a name from translated error code
- $handlerName = 'socketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler';
-
- // Is the call-back method there?
- if (!method_exists($this, $handlerName)) {
- // Please implement this
- throw new UnsupportedSocketErrorHandlerException(array($this, $handlerName, $errorCode), self::EXCEPTION_UNSUPPORTED_ERROR_HANDLER);
- } // END - if
-
- // Return it
- return $handlerName;
- }
-
- /**
- * 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 $unlData A valid UNL data array
- * @return void
- * @throws InvalidSocketException If $socketResource is no socket resource
- * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back
- */
- protected final function handleSocketError ($method, $line, $socketResource, array $unlData) {
- // 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 UNL array
- //* DEBUG-DIE: */ die(__METHOD__ . ':unlData=' . print_r($unlData, TRUE));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
-
- // 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, $unlData));
-
- // Finally clear the error because it has been handled
- socket_clear_error($socketResource);
- }
-
- /**
- * Translates socket error codes into our own internal names which can be
- * used for call-backs.
- *
- * @param $errorCode The error code from socket_last_error() to be translated
- * @return $errorName The translated name (all lower-case, with underlines)
- */
- public function translateSocketErrorCodeToName ($errorCode) {
- // Nothing bad happened by default
- $errorName = BaseRawDataHandler::SOCKET_CONNECTED;
-
- // Is the code a number, then we have to change it
- switch ($errorCode) {
- case 0: // Silently ignored, the socket is connected
- break;
-
- case 11: // "Resource temporary unavailable"
- $errorName = BaseRawDataHandler::SOCKET_ERROR_RESOURCE_UNAVAILABLE;
- break;
-
- case 32: // "Broken pipe"
- $errorName = BaseRawDataHandler::SOCKET_ERROR_BROKEN_PIPE;
- break;
-
- case 104: // "Connection reset by peer"
- $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_RESET_BY_PEER;
- break;
-
- case 107: // "Transport end-point not connected"
- case 134: // On some (?) systems for 'transport end-point not connected'
- // @TODO On some systems it is 134, on some 107?
- $errorName = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
- break;
-
- case 110: // "Connection timed out"
- $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_TIMED_OUT;
- break;
-
- case 111: // "Connection refused"
- $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED;
- break;
-
- case 113: // "No route to host"
- $errorName = BaseRawDataHandler::SOCKET_ERROR_NO_ROUTE_TO_HOST;
- break;
-
- case 114: // "Operation already in progress"
- $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS;
- break;
-
- case 115: // "Operation now in progress"
- $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_IN_PROGRESS;
- break;
-
- default: // Everything else <> 0
- // Unhandled error code detected, so first debug it because we may want to handle it like the others
- self::createDebugInstance(__CLASS__)->debugOutput('BASE-HUB[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode));
-
- // Change it only in this class
- $errorName = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
- break;
- }
-
- // Return translated name
- return $errorName;
- }
-
- /**
- * Shuts down a given socket resource. This method does only ease calling
- * the right visitor.
- *
- * @param $socketResource A valid socket resource
- * @return void
- */
- public function shutdownSocket ($socketResource) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
-
- // Set socket resource
- $this->setSocketResource($socketResource);
-
- // Get a visitor instance
- $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
-
- // Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
-
- // Call the visitor
- $this->accept($visitorInstance);
- }
-
- /**
- * Half-shuts down a given socket resource. This method does only ease calling
- * an other visitor than shutdownSocket() does.
- *
- * @param $socketResource A valid socket resource
- * @return void
- */
- public function halfShutdownSocket ($socketResource) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
-
- // Set socket resource
- $this->setSocketResource($socketResource);
-
- // Get a visitor instance
- $visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class');
-
- // Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
-
- // Call the visitor
- $this->accept($visitorInstance);
- }
-
- /**
- * "Getter" for a printable state name
- *
- * @return $stateName Name of the node's state in a printable format
- */
- public final function getPrintableState () {
- // Default is 'null'
- $stateName = 'null';
-
- // Get the state instance
- $stateInstance = $this->getStateInstance();
-
- // Is it an instance of Stateable?
- if ($stateInstance instanceof Stateable) {
- // Then use that state name
- $stateName = $stateInstance->getStateName();
- } // END - if
-
- // Return result
- return $stateName;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A command for the 'apt-proxy client' routine
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 HubConsoleAptProxyCommand extends BaseCommand implements Commandable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $commandInstance An instance a prepared command class
- */
- public static final function createHubConsoleAptProxyCommand (CommandResolver $resolverInstance) {
- // Get new instance
- $commandInstance = new HubConsoleAptProxyCommand();
-
- // Set the application instance
- $commandInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $commandInstance;
- }
-
- /**
- * Executes the given command with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Try to create a AptProxyActivationTask or so
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a registry and the application instance from it
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- /*
- * ----------------------- Bootstrapping phase ------------------------
- * Try to bootstrap the node and pass the request instance to it for
- * extra arguments which mostly override config entries or enable special
- * features within the hub (none is ready at this development stage)
- */
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
- $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
-
- // Get apt-proxy instance
- $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
-
- // Add some apt-proxy-specific filters
- $proxyInstance->addExtraAptProxyFilters();
-
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
-
- /*
- * ----------------------------- Main loop ----------------------------
- * This is the main loop. Queried calls should come back here very fast
- * so the whole application runs on nice speed. This while-loop goes
- * until the apt-proxy is no longer active or all tasks are killed.
- */
- while (($proxyInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
- // Handle all tasks here
- $handlerInstance->handleTasks();
- } // END - while
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
- }
-
- /**
- * Adds extra filters to the given controller instance
- *
- * @param $controllerInstance A controller instance
- * @param $requestInstance An instance of a class with an Requestable interface
- * @return void
- * @todo Should we add some more filters?
- */
- public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
- // Add pre filters
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_php_requirements_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_initializer_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_welcome_teaser_filter'));
-
- // Add bootstrap filters
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_bootstrap_task_handler_initializer_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_bootstrap_extra_bootstrapping_filter'));
-
- // This is the last generic boostrap filter
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_bootstrap_generic_activation_filter'));
-
- // Add shutdown filters
- //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_shutdown_task_handler_filter'));
-
- // This is the last generic shutdown filter
- $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('apt_proxy_shutdown_filter'));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A command for the 'chat client' routine
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 HubConsoleChatCommand extends BaseCommand implements Commandable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $commandInstance An instance a prepared command class
- */
- public static final function createHubConsoleChatCommand (CommandResolver $resolverInstance) {
- // Get new instance
- $commandInstance = new HubConsoleChatCommand();
-
- // Set the application instance
- $commandInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $commandInstance;
- }
-
- /**
- * Executes the given command with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Try to create a ChatActivationTask or so
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a registry and the application instance from it
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- /*
- * ----------------------- Bootstrapping phase ------------------------
- * Try to bootstrap the node and pass the request instance to it for
- * extra arguments which mostly override config entries or enable special
- * features within the hub (none is ready at this development stage)
- */
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
- $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
-
- // Get chat instance
- $chatInstance = Registry::getRegistry()->getInstance('chat');
-
- // Add some chat-specific filters
- $chatInstance->addExtraChatFilters();
-
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
-
- /*
- * ----------------------------- Main loop ----------------------------
- * This is the main loop. Queried calls should come back here very fast
- * so the whole application runs on nice speed. This while-loop goes
- * until the chat is no longer active or all tasks are killed.
- */
- while (($chatInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
- // Handle all tasks here
- $handlerInstance->handleTasks();
- } // END - while
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
- }
-
- /**
- * Adds extra filters to the given controller instance
- *
- * @param $controllerInstance A controller instance
- * @param $requestInstance An instance of a class with an Requestable interface
- * @return void
- * @todo Should we add some more filters?
- */
- public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
- // Add pre filters
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('chat_php_requirements_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('chat_initializer_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('chat_welcome_teaser_filter'));
-
- // Add bootstrap filters
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('chat_bootstrap_task_handler_initializer_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('chat_bootstrap_extra_bootstrapping_filter'));
-
- // This is the last generic boostrap filter
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('chat_bootstrap_generic_activation_filter'));
-
- // Add shutdown filters
- //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('chat_shutdown_task_handler_filter'));
-
- // This is the last generic shutdown filter
- $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('chat_shutdown_filter'));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A command for the 'crawler client' routine
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 HubConsoleCrawlerCommand extends BaseCommand implements Commandable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $commandInstance An instance a prepared command class
- */
- public static final function createHubConsoleCrawlerCommand (CommandResolver $resolverInstance) {
- // Get new instance
- $commandInstance = new HubConsoleCrawlerCommand();
-
- // Set the application instance
- $commandInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $commandInstance;
- }
-
- /**
- * Executes the given command with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Try to create a CrawlerActivationTask or so
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a registry and the application instance from it
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- /*
- * ----------------------- Bootstrapping phase ------------------------
- * Try to bootstrap the node and pass the request instance to it for
- * extra arguments which mostly override config entries or enable special
- * features within the hub (none is ready at this development stage)
- */
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
- $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
-
- // Get crawler instance
- $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
-
- // Add some crawler-specific filters
- $crawlerInstance->addExtraCrawlerFilters();
-
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
-
- /*
- * ----------------------------- Main loop ----------------------------
- * This is the main loop. Queried calls should come back here very fast
- * so the whole application runs on nice speed. This while-loop goes
- * until the crawler is no longer active or all tasks are killed.
- */
- while (($crawlerInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
- // Handle all tasks here
- $handlerInstance->handleTasks();
- } // END - while
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
- }
-
- /**
- * Adds extra filters to the given controller instance
- *
- * @param $controllerInstance A controller instance
- * @param $requestInstance An instance of a class with an Requestable interface
- * @return void
- * @todo Should we add some more filters?
- */
- public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
- // Add pre filters
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('crawler_php_requirements_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('crawler_initializer_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('crawler_welcome_teaser_filter'));
-
- // Add bootstrap filters
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('crawler_bootstrap_task_handler_initializer_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('crawler_bootstrap_extra_bootstrapping_filter'));
-
- // This is the last generic boostrap filter
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('crawler_bootstrap_generic_activation_filter'));
-
- // Add shutdown filters
- //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('crawler_shutdown_task_handler_filter'));
-
- // This is the last generic shutdown filter
- $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('crawler_shutdown_filter'));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A command for the 'cruncher client' routine
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 HubConsoleCruncherCommand extends BaseCommand implements Commandable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $commandInstance An instance a prepared command class
- */
- public static final function createHubConsoleCruncherCommand (CommandResolver $resolverInstance) {
- // Get new instance
- $commandInstance = new HubConsoleCruncherCommand();
-
- // Set the application instance
- $commandInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $commandInstance;
- }
-
- /**
- * Executes the given command with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Try to create a CruncherActivationTask or so
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a registry and the application instance from it
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- /*
- * ----------------------- Bootstrapping phase ------------------------
- * Try to bootstrap the node and pass the request instance to it for
- * extra arguments which mostly override config entries or enable special
- * features within the hub (none is ready at this development stage)
- */
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
- $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
-
- // Get cruncher instance
- $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
-
- // Add some cruncher-specific filters
- $cruncherInstance->addExtraCruncherFilters();
-
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
-
- /*
- * ----------------------------- Main loop ----------------------------
- * This is the main loop. Queried calls should come back here very fast
- * so the whole application runs on nice speed. This while-loop goes
- * until the cruncher is no longer active or all tasks are killed.
- */
- while (($cruncherInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
- // Handle all tasks here
- $handlerInstance->handleTasks();
- } // END - while
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
- }
-
- /**
- * Adds extra filters to the given controller instance
- *
- * @param $controllerInstance A controller instance
- * @param $requestInstance An instance of a class with an Requestable interface
- * @return void
- * @todo Should we add some more filters?
- */
- public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
- // Add pre filters
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('cruncher_php_requirements_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('cruncher_initializer_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('cruncher_welcome_teaser_filter'));
-
- // Add bootstrap filters
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('cruncher_bootstrap_task_handler_initializer_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('cruncher_bootstrap_extra_bootstrapping_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('cruncher_bootstrap_buffer_queue_initializer_filter'));
-
- // This is the last generic boostrap filter
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('cruncher_bootstrap_generic_activation_filter'));
-
- // Add shutdown filters
- //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('cruncher_shutdown_task_handler_filter'));
-
- // This is the last generic shutdown filter
- $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('cruncher_shutdown_filter'));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A command for the 'main' routine
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubConsoleMainCommand extends BaseCommand implements Commandable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $commandInstance An instance a prepared command class
- */
- public static final function createHubConsoleMainCommand (CommandResolver $resolverInstance) {
- // Get new instance
- $commandInstance = new HubConsoleMainCommand();
-
- // Set the application instance
- $commandInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $commandInstance;
- }
-
- /**
- * Executes the given command with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Try to create a HubActivationTask or so
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a registry and the application instance from it
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- /*
- * ----------------------- Bootstrapping phase ------------------------
- * Try to bootstrap the node and pass the request instance to it for
- * extra arguments which mostly override config entries or enable special
- * features within the hub (none is ready at this development stage)
- */
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
- $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
-
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Add some node-specific filters, e.g. announcement
- $nodeInstance->addExtraNodeFilters();
-
- /*
- * -------------------------- Hub activation --------------------------
- * Activates the node by doing some final preparation steps and setting
- * the attribute $hubIsActive to TRUE.
- */
- $nodeInstance->activateNode($requestInstance, $responseInstance);
-
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
-
- /*
- * ----------------------------- Main loop ----------------------------
- * This is the main loop. Queried calls should come back here very fast
- * so the whole application runs on nice speed. This while-loop goes
- * until the hub is no longer active or all tasks are killed.
- */
- while (($nodeInstance->isNodeActive()) && ($handlerInstance->hasTasksLeft())) {
- // Handle all tasks here
- $handlerInstance->handleTasks();
- } // END - while
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
- }
-
- /**
- * Adds extra filters to the given controller instance
- *
- * @param $controllerInstance A controller instance
- * @param $requestInstance An instance of a class with an Requestable interface
- * @return void
- * @todo Should we add some more filters?
- */
- public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
- // Add pre filters
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_php_requirements_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_initializer_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_welcome_teaser_filter'));
-
- // Add bootstrap filters
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_nodeid_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_sessionid_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_generate_private_key_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_extra_bootstrapping_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('node_bootstrap_listener_pool_filter'));
-
- // Add node activation filters
- $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_task_handler_initializer_filter'));
-
- // Add shutdown filters
- $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_flush_node_list_filter'));
- $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_task_handler_filter'));
-
- // This is the last generic shutdown filter
- $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('node_shutdown_node_filter'));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A command for the 'miner client' routine
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Miner 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 HubConsoleMinerCommand extends BaseCommand implements Commandable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $commandInstance An instance a prepared command class
- */
- public static final function createHubConsoleMinerCommand (CommandResolver $resolverInstance) {
- // Get new instance
- $commandInstance = new HubConsoleMinerCommand();
-
- // Set the application instance
- $commandInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $commandInstance;
- }
-
- /**
- * Executes the given command with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Try to create a MinerActivationTask or so
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a registry and the application instance from it
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- /*
- * ----------------------- Bootstrapping phase ------------------------
- * Try to bootstrap the node and pass the request instance to it for
- * extra arguments which mostly override config entries or enable special
- * features within the hub (none is ready at this development stage)
- */
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...');
- $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance);
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.');
-
- // Get miner instance
- $minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Add some miner-specific filters
- $minerInstance->addExtraMinerFilters();
-
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
-
- /*
- * ----------------------------- Main loop ----------------------------
- * This is the main loop. Queried calls should come back here very fast
- * so the whole application runs on nice speed. This while-loop goes
- * until the miner is no longer active or all tasks are killed.
- */
- while (($minerInstance->isActive()) && ($handlerInstance->hasTasksLeft())) {
- // Handle all tasks here
- $handlerInstance->handleTasks();
- } // END - while
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---');
- }
-
- /**
- * Adds extra filters to the given controller instance
- *
- * @param $controllerInstance A controller instance
- * @param $requestInstance An instance of a class with an Requestable interface
- * @return void
- * @todo Should we add some more filters?
- */
- public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
- // Add pre filters
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('miner_php_requirements_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('miner_initializer_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('miner_welcome_teaser_filter'));
-
- // Add bootstrap filters
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_task_handler_initializer_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_extra_bootstrapping_filter'));
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_buffer_queue_initializer_filter'));
-
- // This is the last generic boostrap filter
- $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_generic_activation_filter'));
-
- // Add shutdown filters
- //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('miner_shutdown_task_handler_filter'));
-
- // This is the last generic shutdown filter
- $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('miner_shutdown_filter'));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A command for the 'main' routine
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2015 City 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 HubHtmlIndexCommand extends BaseCommand implements Commandable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $commandInstance An instance a prepared command class
- */
- public static final function createHubHtmlIndexCommand (CommandResolver $resolverInstance) {
- // Get new instance
- $commandInstance = new HubHtmlIndexCommand();
-
- // Set the application instance
- $commandInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $commandInstance;
- }
-
- /**
- * Executes the given command with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // This command doesn't handle any POST requests, so only handle get request
- if ($requestInstance->isPostRequestMethod()) {
- // Don't handle this here
- $response->sendRequestMethodNotAllowed();
-
- // Bail out
- exit();
- } // END - if
-
- /*
- * This is a generic HTML request, this means that a regular page with
- * header, menu, content and footer shall be send to the client.
- */
- $this->sendGenericGetResponse($requestInstance, $responseInstance);
- }
-
- /**
- * Adds extra filters to the given controller instance
- *
- * @param $controllerInstance A controller instance
- * @param $requestInstance An instance of a class with an Requestable interface
- * @return void
- * @todo 0% done
- */
- public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
- // Add pre filters
- //$controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('node_php_requirements_filter'));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ???->node communicator class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 !!! Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???NodeCommunicator extends BaseCommunicator implements Communicator {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $communicatorInstance An instance of a Communicator class
- */
- public final static function create???NodeCommunicator () {
- // Get new instance
- $communicatorInstance = new ???NodeCommunicator();
-
- // Return the prepared instance
- return $communicatorInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general communicator class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 BaseCommunicator extends BaseHubSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Init state which sets the state to 'init'
- $this->initState();
- }
-
- /**
- * Initializes the communicator's state which sets it to 'init'
- *
- * @return void
- */
- private function initState() {
- // Get the state factory and create the initial state.
- CommunicatorStateFactory::createCommunicatorStateInstanceByName('init', $this);
- }
-
- /**
- * Initializes the executor, whatever it does.
- *
- * @return void
- */
- public function initExecutor (Stateable $stateInstance) {
- $this->partialStub('Unfinished method with state ' . $this->getPrintableState() . '.');
-
- // This communicator is now fully initialized so change the state
- $stateInstance->communicatorHasInitialized();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A crawler->node communicator class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerNodeCommunicator extends BaseCommunicator implements Communicator, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $communicatorInstance An instance of a Communicator class
- */
- public final static function createCrawlerNodeCommunicator () {
- // Get new instance
- $communicatorInstance = new CrawlerNodeCommunicator();
-
- // Return the prepared instance
- return $communicatorInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A miner->node communicator class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 MinerNodeCommunicator extends BaseCommunicator implements Communicator, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $communicatorInstance An instance of a Communicator class
- */
- public final static function createMinerNodeCommunicator () {
- // Get new instance
- $communicatorInstance = new MinerNodeCommunicator();
-
- // Return the prepared instance
- return $communicatorInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A NetworkPackageCompressor decorator class. This decorator can later be
- * easily extended without changing any other code.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NetworkPackageCompressorDecorator extends BaseHubSystem implements Compressor {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $innerCompressorInstance The inner Compressor class
- * @return $compressorInstance An instance of a Compressor class
- */
- public static final function createNetworkPackageCompressorDecorator (Compressor $innerCompressorInstance) {
- // Get new instance
- $compressorInstance = new NetworkPackageCompressorDecorator();
-
- // Set the inner compressor class
- $compressorInstance->setCompressorInstance($innerCompressorInstance);
-
- // Return the prepared instance
- return $compressorInstance;
- }
-
- /**
- * A compression stream
- *
- * @param $streamData Mixed non-object stream data
- * @return $streamData The compressed stream data
- * @throws InvalidObjectException If the stream is an object
- */
- public function compressStream ($streamData) {
- // Call the inner compressor class
- return $this->getCompressorInstance()->compressStream($streamData);
- }
-
- /**
- * A decompression stream
- *
- * @param $streamData Mixed non-object stream data
- * @return $streamData The decompressed stream data
- * @throws InvalidObjectException If the stream is an object
- */
- public function decompressStream ($streamData) {
- // Call the inner compressor class
- return $this->getCompressorInstance()->decompressStream($streamData);
- }
-
- /**
- * Getter for the file extension of this compressor
- *
- * @return $string The compressor's file extension
- */
- public function getCompressorExtension () {
- // Call the inner compressor class
- return $this->getCompressorInstance()->getCompressorExtension();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A console controller for the apt-proxy program.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 HubConsoleAptProxyController extends BaseController implements Controller {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init additional filter chains
- foreach (array('bootstrap','shutdown') as $filterChain) {
- $this->initFilterChain($filterChain);
- } // END - foreach
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $controllerInstance A prepared instance of this class
- */
- public static final function createHubConsoleAptProxyController (CommandResolver $resolverInstance) {
- // Create the instance
- $controllerInstance = new HubConsoleAptProxyController();
-
- // Set the command resolver
- $controllerInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $controllerInstance;
- }
-
- /**
- * Handles the given request and response
- *
- * @param $requestInstance An instance of a request class
- * @param $responseInstance An instance of a response class
- * @return void
- */
- public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
- // Get the command instance from the resolver by sending a request instance to the resolver
- $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
-
- // Add more filters by the command
- $commandInstance->addExtraFilters($this, $requestInstance);
-
- // Run the pre filters
- $this->executePreFilters($requestInstance, $responseInstance);
-
- // This request was valid! :-D
- $requestInstance->requestIsValid();
-
- // Execute the command
- $commandInstance->execute($requestInstance, $responseInstance);
-
- // Run the pre filters
- $this->executePostFilters($requestInstance, $responseInstance);
-
- // Flush the response out
- $responseInstance->flushBuffer();
- }
-
- /**
- * Add a bootstrap filter
- *
- * @param $filterInstance A Filterable class
- * @return void
- */
- public function addBootstrapFilter (Filterable $filterInstance) {
- $this->addFilter('bootstrap', $filterInstance);
- }
-
- /**
- * Executes all bootstrap filters
- *
- * @param $requestInstance A Requestable class
- * @param $responseInstance A Responseable class
- * @return void
- */
- public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
- $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A console controller for the chat program.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 HubConsoleChatController extends BaseController implements Controller {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init additional filter chains
- foreach (array('bootstrap','shutdown') as $filterChain) {
- $this->initFilterChain($filterChain);
- } // END - foreach
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $controllerInstance A prepared instance of this class
- */
- public static final function createHubConsoleChatController (CommandResolver $resolverInstance) {
- // Create the instance
- $controllerInstance = new HubConsoleChatController();
-
- // Set the command resolver
- $controllerInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $controllerInstance;
- }
-
- /**
- * Handles the given request and response
- *
- * @param $requestInstance An instance of a request class
- * @param $responseInstance An instance of a response class
- * @return void
- */
- public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
- // Get the command instance from the resolver by sending a request instance to the resolver
- $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
-
- // Add more filters by the command
- $commandInstance->addExtraFilters($this, $requestInstance);
-
- // Run the pre filters
- $this->executePreFilters($requestInstance, $responseInstance);
-
- // This request was valid! :-D
- $requestInstance->requestIsValid();
-
- // Execute the command
- $commandInstance->execute($requestInstance, $responseInstance);
-
- // Run the pre filters
- $this->executePostFilters($requestInstance, $responseInstance);
-
- // Flush the response out
- $responseInstance->flushBuffer();
- }
-
- /**
- * Add a bootstrap filter
- *
- * @param $filterInstance A Filterable class
- * @return void
- */
- public function addBootstrapFilter (Filterable $filterInstance) {
- $this->addFilter('bootstrap', $filterInstance);
- }
-
- /**
- * Executes all bootstrap filters
- *
- * @param $requestInstance A Requestable class
- * @param $responseInstance A Responseable class
- * @return void
- */
- public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
- $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A console controller for the crawler program.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 HubConsoleCrawlerController extends BaseController implements Controller {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init additional filter chains
- foreach (array('bootstrap','shutdown') as $filterChain) {
- $this->initFilterChain($filterChain);
- } // END - foreach
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $controllerInstance A prepared instance of this class
- */
- public static final function createHubConsoleCrawlerController (CommandResolver $resolverInstance) {
- // Create the instance
- $controllerInstance = new HubConsoleCrawlerController();
-
- // Set the command resolver
- $controllerInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $controllerInstance;
- }
-
- /**
- * Handles the given request and response
- *
- * @param $requestInstance An instance of a request class
- * @param $responseInstance An instance of a response class
- * @return void
- */
- public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
- // Get the command instance from the resolver by sending a request instance to the resolver
- $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
-
- // Add more filters by the command
- $commandInstance->addExtraFilters($this, $requestInstance);
-
- // Run the pre filters
- $this->executePreFilters($requestInstance, $responseInstance);
-
- // This request was valid! :-D
- $requestInstance->requestIsValid();
-
- // Execute the command
- $commandInstance->execute($requestInstance, $responseInstance);
-
- // Run the pre filters
- $this->executePostFilters($requestInstance, $responseInstance);
-
- // Flush the response out
- $responseInstance->flushBuffer();
- }
-
- /**
- * Add a bootstrap filter
- *
- * @param $filterInstance A Filterable class
- * @return void
- */
- public function addBootstrapFilter (Filterable $filterInstance) {
- $this->addFilter('bootstrap', $filterInstance);
- }
-
- /**
- * Executes all bootstrap filters
- *
- * @param $requestInstance A Requestable class
- * @param $responseInstance A Responseable class
- * @return void
- */
- public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
- $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A console controller for the cruncher, which is our very first hub
- * application.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 HubConsoleCruncherController extends BaseController implements Controller {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init additional filter chains
- foreach (array('bootstrap','shutdown') as $filterChain) {
- $this->initFilterChain($filterChain);
- } // END - foreach
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $controllerInstance A prepared instance of this class
- */
- public static final function createHubConsoleCruncherController (CommandResolver $resolverInstance) {
- // Create the instance
- $controllerInstance = new HubConsoleCruncherController();
-
- // Set the command resolver
- $controllerInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $controllerInstance;
- }
-
- /**
- * Handles the given request and response
- *
- * @param $requestInstance An instance of a request class
- * @param $responseInstance An instance of a response class
- * @return void
- */
- public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
- // Get the command instance from the resolver by sending a request instance to the resolver
- $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
-
- // Add more filters by the command
- $commandInstance->addExtraFilters($this, $requestInstance);
-
- // Run the pre filters
- $this->executePreFilters($requestInstance, $responseInstance);
-
- // This request was valid! :-D
- $requestInstance->requestIsValid();
-
- // Execute the command
- $commandInstance->execute($requestInstance, $responseInstance);
-
- // Run the pre filters
- $this->executePostFilters($requestInstance, $responseInstance);
-
- // Flush the response out
- $responseInstance->flushBuffer();
- }
-
- /**
- * Add a bootstrap filter
- *
- * @param $filterInstance A Filterable class
- * @return void
- */
- public function addBootstrapFilter (Filterable $filterInstance) {
- $this->addFilter('bootstrap', $filterInstance);
- }
-
- /**
- * Executes all bootstrap filters
- *
- * @param $requestInstance A Requestable class
- * @param $responseInstance A Responseable class
- * @return void
- */
- public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
- $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * The default controller with news for e.g. home or news page
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubConsoleDefaultNewsController extends BaseController implements Controller {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init additional filter chains
- foreach (array('bootstrap', 'activation','shutdown') as $filterChain) {
- $this->initFilterChain($filterChain);
- } // END - foreach
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $controllerInstance A prepared instance of this class
- */
- public static final function createHubConsoleDefaultNewsController (CommandResolver $resolverInstance) {
- // Create the instance
- $controllerInstance = new HubConsoleDefaultNewsController();
-
- // Set the command resolver
- $controllerInstance->setResolverInstance($resolverInstance);
-
- // Add news filters to this controller
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter'));
- $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter'));
-
- // Return the prepared instance
- return $controllerInstance;
- }
-
- /**
- * Handles the given request and response
- *
- * @param $requestInstance An instance of a request class
- * @param $responseInstance An instance of a response class
- * @return void
- */
- public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
- // Get the command instance from the resolver by sending a request instance to the resolver
- $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
-
- // Add more filters by the command
- $commandInstance->addExtraFilters($this, $requestInstance);
-
- // Run the pre filters
- $this->executePreFilters($requestInstance, $responseInstance);
-
- // This request was valid! :-D
- $requestInstance->requestIsValid();
-
- // Execute the command
- $commandInstance->execute($requestInstance, $responseInstance);
-
- // Run the pre filters
- $this->executePostFilters($requestInstance, $responseInstance);
-
- // Flush the response out
- $responseInstance->flushBuffer();
- }
-
- /**
- * Add a bootstrap filter
- *
- * @param $filterInstance A Filterable class
- * @return void
- */
- public function addBootstrapFilter (Filterable $filterInstance) {
- $this->addFilter('bootstrap', $filterInstance);
- }
-
- /**
- * Executes all bootstrap filters
- *
- * @param $requestInstance A Requestable class
- * @param $responseInstance A Responseable class
- * @return void
- */
- public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
- $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
- }
-
- /**
- * Add a hub activation filter
- *
- * @param $filterInstance A Filterable class
- * @return void
- */
- public function addActivationFilter (Filterable $filterInstance) {
- $this->addFilter('activation', $filterInstance);
- }
-
- /**
- * Executes all hub activation filters
- *
- * @param $requestInstance A Requestable class
- * @param $responseInstance A Responseable class
- * @return void
- */
- public function executeActivationFilters (Requestable $requestInstance, Responseable $responseInstance) {
- $this->executeFilters('activation', $requestInstance, $responseInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A console controller for the "continued hashing miner".
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Miner 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 HubConsoleMinerController extends BaseController implements Controller {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init additional filter chains
- foreach (array('bootstrap','shutdown') as $filterChain) {
- $this->initFilterChain($filterChain);
- } // END - foreach
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $resolverInstance An instance of a command resolver class
- * @return $controllerInstance A prepared instance of this class
- */
- public static final function createHubConsoleMinerController (CommandResolver $resolverInstance) {
- // Create the instance
- $controllerInstance = new HubConsoleMinerController();
-
- // Set the command resolver
- $controllerInstance->setResolverInstance($resolverInstance);
-
- // Return the prepared instance
- return $controllerInstance;
- }
-
- /**
- * Handles the given request and response
- *
- * @param $requestInstance An instance of a request class
- * @param $responseInstance An instance of a response class
- * @return void
- */
- public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) {
- // Get the command instance from the resolver by sending a request instance to the resolver
- $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance);
-
- // Add more filters by the command
- $commandInstance->addExtraFilters($this, $requestInstance);
-
- // Run the pre filters
- $this->executePreFilters($requestInstance, $responseInstance);
-
- // This request was valid! :-D
- $requestInstance->requestIsValid();
-
- // Execute the command
- $commandInstance->execute($requestInstance, $responseInstance);
-
- // Run the pre filters
- $this->executePostFilters($requestInstance, $responseInstance);
-
- // Flush the response out
- $responseInstance->flushBuffer();
- }
-
- /**
- * Add a bootstrap filter
- *
- * @param $filterInstance A Filterable class
- * @return void
- */
- public function addBootstrapFilter (Filterable $filterInstance) {
- $this->addFilter('bootstrap', $filterInstance);
- }
-
- /**
- * Executes all bootstrap filters
- *
- * @param $requestInstance A Requestable class
- * @param $responseInstance A Responseable class
- * @return void
- */
- public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) {
- $this->executeFilters('bootstrap', $requestInstance, $responseInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A node ??? crawler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Node???Crawler extends BaseNodeCrawler implements Crawler {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $crawlerInstance An instance of a Crawler class
- */
- public final static function createNode???Crawler () {
- // Get new instance
- $crawlerInstance = new Node???Crawler();
-
- // Return the prepared instance
- return $crawlerInstance;
- }
-
- /**
- * Method to "bootstrap" the crawler. This step does also apply provided
- * command-line arguments stored in the request instance. You should now
- * get it from calling $this->getRequestInstance().
- *
- * @return void
- */
- public function doBootstrapping () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Add some crawler-specific filters
- *
- * @param $controllerInstance An object of a Controller instance
- * @param $responseInstance An object of a Responseable instance
- * @return void
- */
- public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general NodeCrawler class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 BaseNodeCrawler extends BaseHubSystem {
- /**
- * Whether this Crawler is active
- */
- private $isActive = FALSE;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Set this crawler instance in registry
- Registry::getRegistry()->addInstance('crawler', $this);
-
- // Init state which sets the state to 'init'
- $this->initState();
- }
-
- /**
- * Initializes the node's state which sets it to 'init'
- *
- * @return void
- */
- private function initState() {
- // Get the state factory and create the initial state.
- CrawlerStateFactory::createCrawlerStateInstanceByName('init');
- }
-
- /**
- * Initializes this crawler instance
- *
- * @param $stateInstance An instance of a Stateable class
- * @return void
- * @todo 0% done
- */
- public function initCrawler (Stateable $stateInstance) {
- // Please implement
- $this->partialStub('Unfinished method.');
- }
-
- /**
- * Enables/disables the crawler (just sets a flag)
- *
- * @param $version Version number of this crawler
- * @return void
- */
- public final function enableIsActive ($isActive = TRUE) {
- $this->isActive = (bool) $isActive;
- }
-
- /**
- * Determines whether the crawler is active
- *
- * @return $isActive Whether the crawler is active
- */
- public final function isActive () {
- return $this->isActive;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A node console crawler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 NodeConsoleCrawler extends BaseNodeCrawler implements Crawler, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $crawlerInstance An instance of a Crawler class
- */
- public final static function createNodeConsoleCrawler () {
- // Get new instance
- $crawlerInstance = new NodeConsoleCrawler();
-
- // Return the prepared instance
- return $crawlerInstance;
- }
-
- /**
- * Method to "bootstrap" the crawler. This step does also apply provided
- * command-line arguments stored in the request instance. You should now
- * get it from calling $this->getRequestInstance().
- *
- * @return void
- */
- public function doBootstrapping () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- // Get the app instance (for shortening our code)
- $app = $this->getApplicationInstance();
-
- // Output all lines
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput('Distributed Crawler v' . $app->getAppVersion());
- self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2014 Crawler Developer Team');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
- self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
- self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- }
-
- /**
- * Add some crawler-specific filters
- *
- * @param $controllerInstance An object of a Controller instance
- * @param $responseInstance An object of a Responseable instance
- * @return void
- */
- public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A hub-cruncher class for the '???' mode
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Cruncher Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Hub???Cruncher extends BaseHubCruncher implements CruncherHelper, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set version number
- $this->setVersion('x.x');
- }
-
- /**
- * Creates an instance of this hub-cruncher class
- *
- * @param $requestInstance An instance of a Requestable class
- * @return $cruncherInstance An instance of this hub-cruncher class
- */
- public final static function createHub???Cruncher (Requestable $requestInstance) {
- // Get a new instance
- $cruncherInstance = new Hub???Cruncher();
-
- // Set the request instance
- $cruncherInstance->setRequestInstance($requestInstance);
-
- // Return the instance
- return $cruncherInstance;
- }
-
- /**
- * Method to "bootstrap" the cruncher. This step does also apply provided
- * command-line arguments stored in the request instance. The regular cruncher
- * should communicate with the bootstrap-crunchers at this point.
- *
- * @return void
- * @todo Implement this method
- */
- public function doBootstrapping () {
- // Call generic (parent) bootstrapping method first
- parent::doGenericBootstrapping();
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Add some cruncher-specific filters
- *
- * @return void
- */
- public function addExtraHubFilters () {
- // Add some filters here
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general hub cruncher class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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/>.
- */
-abstract class BaseHubCruncher extends BaseHubSystem implements Updateable {
- /**
- * Version information
- */
- private $version = 'x.x';
-
- /**
- * By default no cruncher is active
- */
- private $isActive = FALSE;
-
- /**
- * All buffer queue instances (a FIFO)
- */
- private $bufferInstance = NULL;
-
- /**
- * Stacker name for incoming queue
- */
- const STACKER_NAME_IN_QUEUE = 'in_queue';
-
- /**
- * Stacker name for outcoming queue
- */
- const STACKER_NAME_OUT_QUEUE = 'out_queue';
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Set this cruncher instance in registry
- Registry::getRegistry()->addInstance('cruncher', $this);
-
- // Init this cruncher
- $this->initCruncher();
- }
-
- /**
- * Initialize the cruncher generically
- *
- * @return void
- */
- private function initCruncher () {
- // Init the state
- CruncherStateFactory::createCruncherStateInstanceByName('init');
- }
-
- /**
- * Getter for version
- *
- * @return $version Version number of this cruncher
- */
- protected final function getVersion () {
- return $this->version;
- }
-
- /**
- * Setter for version
- *
- * @param $version Version number of this cruncher
- * @return void
- */
- protected final function setVersion ($version) {
- $this->version = (string) $version;
- }
-
- /**
- * Checks whether the in-buffer queue is filled by comparing it's current
- * amount of entries against a threshold.
- *
- * @return $isFilled Whether the in-buffer is filled
- */
- protected function isInBufferQueueFilled () {
- // Determine it
- $isFilled = ($this->bufferInstance->getStackCount(self::STACKER_NAME_IN_QUEUE) > $this->getConfigInstance()->getConfigEntry('cruncher_in_buffer_min_threshold'));
-
- // And return the result
- return $isFilled;
- }
-
- /**
- * This method fills the in-buffer with (a) test unit(s) which are mainly
- * used for development of the crunching part. They must be enabled in
- * configuration, or else your cruncher runs out of WUs and waits for more
- * to show up.
- *
- * In this method we already know that the in-buffer is going depleted so
- * no need to double-check it here.
- *
- * @return void
- */
- abstract protected function fillInBufferQueueWithTestUnits ();
-
- /**
- * This method fills the in-buffer with (real) WUs which will be crunched
- * and the result be sent back to the key producer instance.
- *
- * @return void
- */
- abstract protected function fillInBufferQueueWithWorkUnits ();
-
- /**
- * Enables/disables the cruncher (just sets a flag)
- *
- * @param $version Version number of this cruncher
- * @return void
- */
- public final function enableIsActive ($isActive = TRUE) {
- $this->isActive = (bool) $isActive;
- }
-
- /**
- * Determines whether the cruncher is active
- *
- * @return $isActive Whether the cruncher is active
- */
- public final function isActive () {
- return $this->isActive;
- }
-
- /**
- * Initializes all buffer queues (mostly in/out). This method is demanded
- * by the CruncherHelper interface.
- *
- * @return void
- */
- public function initBufferQueues () {
- /*
- * Initialize both buffer queues, we can use the FIFO class here
- * directly and encapsulate its method calls with protected methods.
- */
- $this->bufferInstance = ObjectFactory::createObjectByConfiguredName('cruncher_buffer_stacker_class');
-
- // Initialize common stackers, like in/out
- $this->bufferInstance->initStacks(array(
- self::STACKER_NAME_IN_QUEUE,
- self::STACKER_NAME_OUT_QUEUE
- ));
-
- // Output debug message
- self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER: All buffers are now initialized.');
- }
-
- /**
- * This method determines if the in-buffer is going to depleted and if so,
- * it fetches more WUs from the network. If no WU can be fetched from the
- * network and if enabled, a random test WU is being generated.
- *
- * This method is demanded from the CruncherHelper interface.
- *
- * @return void
- */
- public function doFetchWorkUnits () {
- // Simply check if we have enough WUs left in the in-buffer queue (a FIFO)
- if (!$this->isInBufferQueueFilled()) {
- // The in-buffer queue needs filling, so head out and get some work
- $this->fillInBufferQueueWithWorkUnits();
-
- // Is the buffer still not filled and are test-packages allowed?
- if ((!$this->isInBufferQueueFilled()) && ($this->getConfigInstance()->getConfigEntry('cruncher_test_units_enabled') == 'Y')) {
- // Then fill the in-buffer with (one) test-unit(s)
- $this->fillInBufferQueueWithTestUnits();
- } // END - if
- } // END - if
- }
-
- /**
- * Updates a given field with new value
- *
- * @param $fieldName Field to update
- * @param $fieldValue New value to store
- * @return void
- * @throws DatabaseUpdateSupportException If this class does not support database updates
- * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
- */
- public function updateDatabaseField ($fieldName, $fieldValue) {
- // Unfinished
- $this->partialStub('Unfinished!');
- return;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A hub-mcrypt cruncher class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 HubMcryptCruncher extends BaseHubCruncher implements CruncherHelper, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set version number
- $this->setVersion('0.0.0');
- }
-
- /**
- * Creates an instance of this hub-cruncher class
- *
- * @return $cruncherInstance An instance of this hub-cruncher class
- */
- public final static function createHubMcryptCruncher () {
- // Get a new instance
- $cruncherInstance = new HubMcryptCruncher();
-
- // Return the instance
- return $cruncherInstance;
- }
-
- /**
- * This method fills the in-buffer with (a) test unit(s) which are mainly
- * used for development of the crunching part. They must be enabled in
- * configuration, or else your cruncher runs out of WUs and waits for more
- * to show up.
- *
- * In this method we already know that the in-buffer is going depleted so
- * no need to double-check it here.
- *
- * @return void
- */
- protected function fillInBufferQueueWithTestUnits () {
- // Are test units enabled?
- if ($this->getConfigInstance()->getConfigEntry('cruncher_test_units_enabled') == 'N') {
- // They are disabled, so skip any further steps
- return;
- } elseif ($this->getStateInstance()->isCruncherStateVirgin()) {
- // No virgin crunchers please, because they usually have no test units ready for crunching
- return;
- }
-
- // Get a test-unit generator instance
- $generatorInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_generator_class');
-
- // We don't need an iterator here because we just need to generate some test units
- for ($idx = 0; $idx < $this->getConfigInstance()->getConfigEntry('cruncher_max_text_unit_amount'); $idx++) {
- // Get a test unit from it
- $unitInstance = $generatorInstance->generateNextUnitInstance();
-
- // ... and finally queue it to the in-buffer queue
- $this->queueUnitInstanceToInBuffer($unitInstance);
- } // END - for
- }
-
- /**
- * This method fills the in-buffer with (real) WUs which will be crunched
- * and the result be sent back to the key producer instance.
- *
- * @return void
- */
- protected function fillInBufferQueueWithWorkUnits () {
- // This cruncher's state must not be one of these: 'virgin'
- if ($this->getStateInstance()->isCruncherStateVirgin()) {
- // We can silently skip here, until the generation is finished
- return;
- } // END - if
-
- // @TODO Implement this method
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Method to "bootstrap" the cruncher. This step does also apply provided
- * command-line arguments stored in the request instance. No buffer queue
- * will be initialized here, we only do "general" things here.
- *
- * @return void
- * @todo Implement this method
- */
- public function doBootstrapping () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- // Output all lines
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput('MCrypt Cruncher v' . $this->getVersion() . ' is starting ...');
- self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2011 - 2014 Cruncher Developer Team');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
- self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
- self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- }
-
- /**
- * Add some cruncher-specific filters
- *
- * @param $controllerInstance An object of a Controller instance
- * @param $responseInstance An object of a Responseable instance
- * @return void
- * @todo 0% done
- */
- public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
- // Add some filters here
- $this->partialStub('Please add some cruncher-specific filters, if required.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A database wrapper for cruncher work/test units
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherUnitDatabaseWrapper extends BaseDatabaseWrapper implements UnitDatabaseWrapper, Registerable {
- // Constants for database table names
- const DB_TABLE_CRUNCHER_UNITS = 'cruncher_units';
-
- // Constants for database column names
- const DB_COLUMN_UNIT_TYPE = 'unit_type';
- const DB_COLUMN_UNIT_STATUS = 'unit_status';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this database wrapper by a provided user class
- *
- * @return $wrapperInstance An instance of the created wrapper class
- */
- public static final function createCruncherUnitDatabaseWrapper () {
- // Get a new instance
- $wrapperInstance = new CruncherUnitDatabaseWrapper();
-
- // Set (primary!) table name
- $wrapperInstance->setTableName(self::DB_TABLE_CRUNCHER_UNITS);
-
- // Return the instance
- return $wrapperInstance;
- }
-
- /**
- * Checks whether a test unit has been produced
- *
- * @return $isProduced Whether a test unit has already been produced
- */
- public function isTestUnitProduced () {
- // Now get a search instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Add criteria for looking up already created and available test units
- $searchInstance->addCriteria(self::DB_COLUMN_UNIT_TYPE , BaseUnitProducer::UNIT_TYPE_TEST_UNIT);
- $searchInstance->addCriteria(self::DB_COLUMN_UNIT_STATUS, BaseUnitProducer::UNIT_STATUS_AVAILABLE);
- $searchInstance->setConfiguredLimit('cruncher_test_unit_max_count');
-
- // Search for our units
- $resultInstance = $this->doSelectByCriteria($searchInstance);
-
- // Do we have some entries?
- $isProduced = $resultInstance->next();
-
- // Return it
- return $isProduced;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A database wrapper for distributed hash tables
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implements NodeDhtWrapper, Registerable {
- /**
- * "Cached" results for dabase for looking for unpublished entries
- */
- private $unpublishedEntriesInstance = NULL;
-
- // Constants for database table names
- const DB_TABLE_NODE_DHT = 'node_dht';
-
- // Constants for database column names
- const DB_COLUMN_NODE_ID = 'node_id';
- const DB_COLUMN_SESSION_ID = 'session_id';
- const DB_COLUMN_EXTERNAL_ADDRESS = 'external_address';
- const DB_COLUMN_PRIVATE_KEY_HASH = 'private_key_hash';
- const DB_COLUMN_NODE_MODE = 'node_mode';
- const DB_COLUMN_ACCEPTED_OBJECTS = 'accepted_object_types';
- const DB_COLUMN_NODE_LIST = 'node_list';
- const DB_COLUMN_PUBLICATION_STATUS = 'publication_status';
- const DB_COLUMN_ANSWER_STATUS = 'answer_status';
- const DB_COLUMN_ACCEPT_BOOTSTRAP = 'accept_bootstrap';
-
- // Publication status'
- const PUBLICATION_STATUS_PENDING = 'PENDING';
-
- // Exception codes
- const EXCEPTION_NODE_ALREADY_REGISTERED = 0x800;
- const EXCEPTION_NODE_NOT_REGISTERED = 0x801;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this database wrapper by a provided user class
- *
- * @return $wrapperInstance An instance of the created wrapper class
- */
- public static final function createNodeDistributedHashTableDatabaseWrapper () {
- // Get a new instance
- $wrapperInstance = new NodeDistributedHashTableDatabaseWrapper();
-
- // Set (primary!) table name
- $wrapperInstance->setTableName(self::DB_TABLE_NODE_DHT);
-
- // Return the instance
- return $wrapperInstance;
- }
-
- /**
- * Static getter for an array of all DHT database entries
- *
- * @return $elements All elements for the DHT dabase
- */
- public static final function getAllElements () {
- // Create array and ...
- $elements = array(
- self::DB_COLUMN_NODE_ID,
- self::DB_COLUMN_SESSION_ID,
- self::DB_COLUMN_EXTERNAL_ADDRESS,
- self::DB_COLUMN_PRIVATE_KEY_HASH,
- self::DB_COLUMN_NODE_MODE,
- self::DB_COLUMN_ACCEPTED_OBJECTS,
- self::DB_COLUMN_NODE_LIST
- );
-
- // ... return it
- return $elements;
- }
-
- /**
- * Prepares a search instance for given node data
- *
- * @param $nodeData An array with valid node data
- * @return $searchInstance An instance of a SearchCriteria class
- */
- private function prepareSearchInstance (array $nodeData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Assert on array elements
- assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
-
- // Get instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Search for node id and limit it to one entry
- $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]);
- $searchInstance->setLimit(1);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
-
- // Return it
- return $searchInstance;
- }
-
- /**
- * Getter for result instance for unpublished entries
- *
- * @return $unpublishedEntriesInstance Result instance
- */
- public final function getUnpublishedEntriesInstance () {
- return $this->unpublishedEntriesInstance;
- }
-
- /**
- * Prepares a "local" instance of a StoreableCriteria class with all node
- * data for insert/update queries. This data set contains data from *this*
- * (local) node.
- *
- * @return $dataSetInstance An instance of a StoreableCriteria class
- */
- private function prepareLocalDataSetInstance () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Get node/request instances
- $nodeInstance = NodeObjectFactory::createNodeInstance();
- $requestInstance = ApplicationHelper::getSelfInstance()->getRequestInstance();
-
- // Get a dataset instance
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
-
- // Set the primary key
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
-
- // Get Universal Node Locator and "explode" it
- $unlInstance = $nodeInstance->determineUniversalNodeLocator();
-
- // Get UNL data from it
- $unlData = $unlInstance->getUnlData();
-
- // Make sure both is valid
- // @TODO Bad check on UNL, better use a proper validator
- assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]));
- assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] !== 'invalid');
-
- // Get an array of all accepted object types
- $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
-
- // Make sure this is an array
- assert(is_array($objectList));
-
- // Add public node data
- $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE , $requestInstance->getRequestElement('mode'));
- $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]);
- $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
- $dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
- $dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getPrivateKeyHash());
- $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
- $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPT_BOOTSTRAP, $this->translateBooleanToYesNo($nodeInstance->isAcceptingDhtBootstrap()));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
-
- // Return it
- return $dataSetInstance;
- }
-
- /**
- * Checks whether the local (*this*) node is registered in the DHT by
- * checking if the external address is found.
- *
- * @return $isRegistered Whether *this* node is registered in the DHT
- */
- public function isLocalNodeRegistered () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Get a search criteria instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Get Universal Node Locator and "explode" it
- $unlData = $nodeInstance->getUniversalNodeLocatorArray();
-
- // Make sure the external address is set and not invalid
- // @TODO Bad check on UNL, better use a proper validator
- assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]));
- assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] != 'invalid');
-
- // Add Universal Node Locator/node id as criteria
- $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]);
- $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
- $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
- $searchInstance->setLimit(1);
-
- // Query database and get a result instance back
- $resultInstance = $this->doSelectByCriteria($searchInstance);
-
- // Cache result of if there is an entry, valid() will tell us if an entry is there
- $isRegistered = $resultInstance->valid();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
-
- // Return result
- return $isRegistered;
- }
-
- /**
- * Registeres the local (*this*) node with its data in the DHT.
- *
- * @return void
- */
- public function registerLocalNode () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Assert to make sure this method is called with no record in DB (the actual backend of the DHT)
- assert(!$this->isLocalNodeRegistered());
-
- // Get prepared data set instance
- $dataSetInstance = $this->prepareLocalDataSetInstance();
-
- // "Insert" this dataset instance completely into the database
- $this->queryInsertDataSet($dataSetInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Updates local (*this*) node's data in DHT, this is but not limited to the
- * session id, ip number (and/or hostname) and port number.
- *
- * @return void
- */
- public function updateLocalNode () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Assert to make sure this method is called with one record in DB (the actual backend of the DHT)
- assert($this->isLocalNodeRegistered());
-
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Get search criteria
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Search for node id and limit it to one entry
- $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeInstance->getNodeId());
- $searchInstance->setLimit(1);
-
- // Get a prepared dataset instance
- $dataSetInstance = $this->prepareLocalDataSetInstance();
-
- // Set search instance
- $dataSetInstance->setSearchInstance($searchInstance);
-
- // Update DHT database record
- $this->queryUpdateDataSet($dataSetInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Finds a node locally by given session id
- *
- * @param $sessionId Session id to lookup
- * @return $nodeData Node data array
- */
- public function findNodeLocalBySessionId ($sessionId) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ' - CALLED!');
-
- // Get search criteria
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Search for session id and limit it to one entry
- $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID, $sessionId);
- $searchInstance->setLimit(1);
-
- // Query database and get a result instance back
- $resultInstance = $this->doSelectByCriteria($searchInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!');
-
- // Return result instance
- return $resultInstance;
- }
-
- /**
- * Registeres a node by given message data.
- *
- * @param $messageData An array of all message data
- * @param $handlerInstance An instance of a HandleableDataSet class
- * @return void
- */
- public function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: handlerInstance=' . $handlerInstance->__toString() . ' - CALLED!');
-
- // Get a data set instance
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
-
- // Set primary key (session id)
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
-
- // Add all array elements
- $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData);
-
- // Remove 'node_list'
- $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
-
- // Run the "INSERT" query
- $this->queryInsertDataSet($dataSetInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . '] - EXIT!');
- }
-
- /**
- * Updates an existing entry in node list
- *
- * @param $messageData An array of all message data
- * @param $handlerInstance An instance of a HandleableDataSet class
- * @param $searchInstance An instance of LocalSearchCriteria class
- * @return void
- */
- public function updateNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Get a data set instance
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
-
- // Add search instance
- $dataSetInstance->setSearchInstance($searchInstance);
-
- // Set primary key (session id)
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
-
- // Add all array elements
- $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData);
-
- // Remove 'node_list'
- $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
-
- // Run the "UPDATE" query
- $this->queryUpdateDataSet($dataSetInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Determines whether the given node data is already inserted in the DHT
- *
- * @param $nodeData An array with valid node data
- * @return $isRegistered Whether the given node data is already inserted
- */
- public function isNodeRegistered (array $nodeData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Assert on array elements
- assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]);
-
- // Get search criteria
- $searchInstance = $this->prepareSearchInstance($nodeData);
-
- // Query database and get a result instance back
- $resultInstance = $this->doSelectByCriteria(
- // Search instance
- $searchInstance,
- // Only look for these array elements ("keys")
- array(
- self::DB_COLUMN_NODE_ID => TRUE,
- self::DB_COLUMN_EXTERNAL_ADDRESS => TRUE
- )
- );
-
- // Check if there is an entry
- $isRegistered = $resultInstance->valid();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
-
- // Return registration status
- return $isRegistered;
- }
-
- /**
- * Registers a node with given data in the DHT. If the node is already
- * registered this method shall throw an exception.
- *
- * @param $nodeData An array with valid node data
- * @return void
- * @throws NodeAlreadyRegisteredException If the node is already registered
- */
- public function registerNode (array $nodeData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Assert on array elements
- assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
-
- // Is the node registered?
- if ($this->isNodeRegistered($nodeData)) {
- // Throw an exception
- throw new NodeAlreadyRegisteredException(array($this, $nodeData), self::EXCEPTION_NODE_ALREADY_REGISTERED);
- } // END - if
-
- // @TODO Unimplemented part
- $this->partialStub('nodeData=' . print_r($nodeData, TRUE));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Updates a node's entry in the DHT with given data. This will enrich or
- * just update already exsiting data. If the node is not found this method
- * shall throw an exception.
- *
- * @param $nodeData An array with valid node data
- * @return void
- * @throws NodeDataMissingException If the node's data is missing
- */
- public function updateNode (array $nodeData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Assert on array elements
- assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...');
-
- // Is the node registered?
- if (!$this->isNodeRegistered($nodeData)) {
- // No, then throw an exception
- throw new NodeDataMissingException(array($this, $nodeData), self::EXCEPTION_NODE_NOT_REGISTERED);
- } // END - if
-
- // Get a search instance
- $searchInstance = $this->prepareSearchInstance($nodeData);
-
- // Get a data set instance
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
-
- // Add search instance
- $dataSetInstance->setSearchInstance($searchInstance);
-
- // Set primary key (session id)
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
-
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: nodeData=' . print_r($nodeData, TRUE));
-
- // Add all array elements
- $nodeInstance->addArrayToDataSet($dataSetInstance, $nodeData);
-
- // Remove 'node_list'
- $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
-
- // Run the "UPDATE" query
- $this->queryUpdateDataSet($dataSetInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Checks whether there are unpublished entries
- *
- * @return $hasUnpublished Whether there are unpublished entries
- * @todo Add minimum/maximum age limitations
- */
- public function hasUnpublishedEntries () {
- // Get search instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Add exclusion key which is the publish status
- $searchInstance->addExcludeCriteria(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PUBLICATION_STATUS, NodeDistributedHashTableDatabaseWrapper::PUBLICATION_STATUS_PENDING);
-
- // Remember search instance
- $this->setSearchInstance($searchInstance);
-
- // Run the query
- $this->unpublishedEntriesInstance = $this->doSelectByCriteria($searchInstance);
-
- // Check pending entries
- $hasUnpublished = $this->unpublishedEntriesInstance->valid();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
-
- // Return it
- return $hasUnpublished;
- }
-
- /**
- * Initializes publication of DHT entries. This does only prepare
- * publication. The next step is to pickup such prepared entries and publish
- * them by uploading to other (recently appeared) DHT members.
- *
- * @return void
- * @todo Add timestamp to dataset instance
- */
- public function initEntryPublication () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- /*
- * Make sure that hasUnpublishedEntries() has been called first by
- * asserting on the "cached" object instance. This "caching" saves some
- * needless queries as this method shall be called immediately after
- * hasUnpublishedEntries() returns TRUE.
- */
- assert($this->unpublishedEntriesInstance instanceof SearchableResult);
-
- // Result is still okay?
- assert($this->unpublishedEntriesInstance->valid());
-
- // Remove 'publication_status'
- $this->getSearchInstance()->unsetCriteria(self::DB_COLUMN_PUBLICATION_STATUS);
-
- // Make sure all entries are marked as pending, first get a dataset instance.
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
-
- // Add search instance
- $dataSetInstance->setSearchInstance($this->getSearchInstance());
-
- // Set primary key (node id)
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
-
- // Add criteria (that should be set)
- $dataSetInstance->addCriteria(self::DB_COLUMN_PUBLICATION_STATUS, self::PUBLICATION_STATUS_PENDING);
-
- // Run the "UPDATE" query
- $this->queryUpdateDataSet($dataSetInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Removes non-public data from given array.
- *
- * @param $data An array with possible non-public data that needs to be removed.
- * @return $data A cleaned up array with only public data.
- */
- public function removeNonPublicDataFromArray(array $data) {
- // Currently call only inner method
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...');
- $data = parent::removeNonPublicDataFromArray($data);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: data[]=' . gettype($data));
-
- // Return cleaned data
- return $data;
- }
-
- /**
- * Find recipients for given package data and exclude the sender
- *
- * @param $packageData An array of valid package data
- * @return $recipients An indexed array with DHT recipients
- */
- public function getResultFromExcludedSender (array $packageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Assert on required array field
- assert(isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER]));
-
- // Get max recipients
- $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
-
- // First creata a search instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Then exclude 'sender' field as the sender is the current (*this*) node
- $searchInstance->addExcludeCriteria(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
-
- // Set limit to maximum DHT recipients
- $searchInstance->setLimit($maxRecipients);
-
- // Get a result instance back from DHT database wrapper.
- $resultInstance = $this->doSelectByCriteria($searchInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
-
- // Return result instance
- return $resultInstance;
- }
-
- /**
- * Find recopients by given key/value pair. First look for the key and if it
- * matches, compare the value.
- *
- * @param $key Key to look for
- * @param $value Value to compare if key matches
- * @return $recipients An indexed array with DHT recipients
- */
- public function getResultFromKeyValue ($key, $value) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Get max recipients
- $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
-
- // First creata a search instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Find the key/value pair
- $searchInstance->addCriteria($key, $value);
-
- // Get a result instance back from DHT database wrapper.
- $resultInstance = $this->doSelectByCriteria($searchInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
-
- // Return result instance
- return $resultInstance;
- }
-
- /**
- * Enable DHT bootstrap request acceptance for local node
- *
- * @return void
- */
- public function enableAcceptDhtBootstrap () {
- // Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...');
-
- // Is the node already registered?
- if ($this->isLocalNodeRegistered()) {
- // Just update our record
- $this->updateLocalNode();
- } else {
- // Register it
- $this->registerLocalNode();
- }
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A database wrapper for node informations
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeInformationDatabaseWrapper extends BaseDatabaseWrapper implements NodeInformationWrapper, Registerable {
- // Constants for database table names
- const DB_TABLE_NODE_INFORMATION = 'node_data';
-
- // Constants for database column names
- const DB_COLUMN_NODE_NR = 'node_nr';
- const DB_COLUMN_NODE_ID = 'node_id';
- const DB_COLUMN_SESSION_ID = 'session_id';
- const DB_COLUMN_PRIVATE_KEY = 'private_key';
- const DB_COLUMN_PRIVATE_KEY_HASH = 'private_key_hash';
- const DB_COLUMN_NODE_MODE = 'node_mode';
- const DB_COLUMN_INTERNAL_UNL = 'internal_unl';
- const DB_COLUMN_EXTERNAL_UNL = 'external_unl';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this database wrapper by a provided user class
- *
- * @return $wrapperInstance An instance of the created wrapper class
- */
- public static final function createNodeInformationDatabaseWrapper () {
- // Get a new instance
- $wrapperInstance = new NodeInformationDatabaseWrapper();
-
- // Set (primary!) table name
- $wrapperInstance->setTableName(self::DB_TABLE_NODE_INFORMATION);
-
- // Return the instance
- return $wrapperInstance;
- }
-
- /**
- * Checks whether there is an entry for given node instance
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return $isFound Whether a node id has been found for this node
- */
- public function ifNodeDataIsFound (NodeHelper $nodeInstance) {
- // Is there cache?
- if (!isset($GLOBALS[__METHOD__])) {
- // Now get a search criteria instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Search for the node number one which is hard-coded the default
- $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
- $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $nodeInstance->getRequestInstance()->getRequestElement('mode'));
- $searchInstance->setLimit(1);
-
- // Get a result back
- $resultInstance = $this->doSelectByCriteria($searchInstance);
-
- // Set result instance in node instance
- $nodeInstance->setResultInstance($resultInstance);
-
- // Is it valid?
- $GLOBALS[__METHOD__] = $resultInstance->next();
- } // END - if
-
- // Return it
- return $GLOBALS[__METHOD__];
- }
-
- /**
- * 'Registers' a new node id along with data provided in the node instance.
- * This may sound confusing but avoids double code very nicely...
- *
- * @param $nodeInstance A node instance
- * @param $requestInstance An instance of a Requestable class
- * @return void
- */
- public function registerNodeId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
- // Get a dataset instance
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
-
- // Set the primary key
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
-
- // Add registration elements to the dataset
- $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
-
- // "Insert" this dataset instance completely into the database
- $this->queryInsertDataSet($dataSetInstance);
- }
-
- /**
- * 'Registers' a new session id along with data provided in the node instance.
- * This may sound confusing but avoids double code very nicely...
- *
- * @param $nodeInstance An instance of a BaseHubNode class
- * @param $requestInstance An instance of a Requestable class
- * @param $searchInstance An instance of a LocalSearchCriteria class
- * @return void
- */
- public function registerSessionId (BaseHubNode $nodeInstance, Requestable $requestInstance, LocalSearchCriteria $searchInstance) {
- // Get a dataset instance
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
-
- // Set search instance
- $dataSetInstance->setSearchInstance($searchInstance);
-
- // Set the primary key
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
-
- // Add registration elements to the dataset
- $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
-
- // Update database record
- $this->queryUpdateDataSet($dataSetInstance);
- }
-
- /**
- * 'Registers' a private key along with data provided in the node instance.
- * This may sound confusing but avoids double code very nicely...
- *
- * @param $nodeInstance An instance of a BaseHubNode class
- * @param $requestInstance An instance of a Requestable class
- * @param $searchInstance An instance of a LocalSearchCriteria class
- * @return void
- */
- public function registerPrivateKey (BaseHubNode $nodeInstance, Requestable $requestInstance, LocalSearchCriteria $searchInstance) {
- // Get a dataset instance
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
-
- // Set the primary key
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
-
- // Set search instance
- $dataSetInstance->setSearchInstance($searchInstance);
-
- // Add registration elements to the dataset
- $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
-
- // Update database record
- $this->queryUpdateDataSet($dataSetInstance);
- }
-
- /**
- * Removes non-public data from given array.
- *
- * @param $data An array with possible non-public data that needs to be removed.
- * @return $data A cleaned up array with only public data.
- */
- public function removeNonPublicDataFromArray(array $data) {
- // Currently call only inner method
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...');
- $data = parent::removeNonPublicDataFromArray($data);
-
- // Return cleaned data
- return $data;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A database wrapper for peer state lookups
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements LookupablePeerState {
- // Exception constants
- const EXCEPTION_PEER_ALREADY_REGISTERED = 0x300;
-
- // Constants for database table names
- const DB_TABLE_PEER_LOOKUP = 'peer_states';
-
- // Constants for database column names
- const DB_COLUMN_PEER_IP = 'peer_ip';
- const DB_COLUMN_PEER_PORT = 'peer_port';
- const DB_COLUMN_PEER_SESSION_ID = 'peer_session_id';
- const DB_COLUMN_PEER_STATE = 'peer_state';
- const DB_COLUMN_SOCKET_ERROR_CODE = 'socket_error_code';
- const DB_COLUMN_SOCKET_ERROR_MSG = 'socket_error_msg';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this database wrapper by a provided user class
- *
- * @return $wrapperInstance An instance of the created wrapper class
- */
- public static final function createPeerStateLookupDatabaseWrapper () {
- // Get a new instance
- $wrapperInstance = new PeerStateLookupDatabaseWrapper();
-
- // Set (primary!) table name
- $wrapperInstance->setTableName(self::DB_TABLE_PEER_LOOKUP);
-
- // Return the instance
- return $wrapperInstance;
- }
-
- /**
- * "Getter" for a LocalSearchCriteria from given package data's sender
- *
- * @param $packageData Valid raw package data array
- * @return $searchInstance An instance of a LocalSearchCriteria class
- */
- private function getSenderSearchInstanceFromPackageData (array $packageData) {
- // Get the instance
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: Searching for sender ' . $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Add 'sender' as the peer's IP address
- $searchInstance->addCriteria(self::DB_COLUMN_PEER_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
- $searchInstance->setLimit(1);
-
- // Return the instance
- return $searchInstance;
- }
-
- /**
- * Checks whether given 'sender' is a new peer
- *
- * @param $packageData Raw package data
- * @param $dataSetInstance An optional instance of a StoreableCriteria class
- * @return $isNewPeer Whether 'sender' is a new peer to this peer
- */
- public function isSenderNewPeer (array $packageData, StoreableCriteria $dataSetInstance = NULL) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: ' . __FUNCTION__ . ' called with packageData()=' . count($packageData) . ' - CALLED!');
-
- // Is the package valid?
- if (!isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER])) {
- // Invalid package found, please report this
- $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE));
- } // END - if
-
- // Get a search criteria instance from package data
- $searchInstance = $this->getSenderSearchInstanceFromPackageData($packageData);
-
- // Is the dataset instance set?
- if ($dataSetInstance instanceof StoreableCriteria) {
- // Then remember the search instance in it
- $dataSetInstance->setSearchInstance($searchInstance);
- } // END - if
-
- // Count the query
- $entries = $this->doSelectCountByCriteria($searchInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE));
-
- // Is it there?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: entries=' . $entries);
- $isNewPeer = ($entries != 1);
-
- // Return the result
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: isNewPeer=' . intval($isNewPeer) . ' - EXIT!');
- return $isNewPeer;
- }
-
- /**
- * Registers a new peer with given package data. We use the session id from it.
- *
- * @param $packageData Raw package data
- * @param $socketResource A valid socket resource
- * @return void
- * @throws PeerAlreadyRegisteredException If a peer is already registered
- */
- public function registerPeerByPackageData (array $packageData, $socketResource) {
- // Make sure only new peers can be registered with package data
- if (!$this->isSenderNewPeer($packageData)) {
- // Throw an exception because this should normally not happen
- throw new PeerAlreadyRegisteredException(array($this, $packageData), self::EXCEPTION_PEER_ALREADY_REGISTERED);
- } // END - if
-
- // Generate a dataset instance
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_PEER_LOOKUP));
-
- // Session ids must be unique
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_PEER_SESSION_ID);
-
- // Add session id
- $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
-
- // Get peer name
- if (!@socket_getpeername($socketResource, $peerName, $peerPort)) {
- // Get last error
- $lastError = socket_last_error($socketResource);
-
- // ... and cleartext message from it and put both into criteria
- $dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_CODE, $lastError);
- $dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_MSG , socket_strerror($lastError));
- } // END - if
-
- // Add ip address and port
- $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_IP , $peerName);
- $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_PORT, $peerPort);
-
- // "Insert" the data set
- $this->queryInsertDataSet($dataSetInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: Peer ' . $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . ' has been registered.');
- }
-
- /**
- * Registers the given peer state and raw package data
- *
- * @param $stateInstance A PeerStateable class instance
- * @param $packageData Valid package data array
- * @return void
- * @throws PeerAlreadyRegisteredException If a peer is already registered
- * @todo Unfinished area
- */
- public function registerPeerState (PeerStateable $stateInstance, array $packageData) {
- // Generate a dataset instance
- $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_PEER_LOOKUP));
-
- // Session ids must be unique
- $dataSetInstance->setUniqueKey(self::DB_COLUMN_PEER_SESSION_ID);
-
- // Add session id
- $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
- $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_STATE , $stateInstance->getStateName());
-
- // Try to resolve sender's session id
- $senderData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_SENDER]));
-
- // Just make sure that 'invalid:invalid' is not being processed
- assert(($senderData[0] != 'invalid') && ($senderData[1] != 'invalid') && ($senderData[2] != 'invalid'));
-
- // Add ip address and port
- $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_IP , $senderData[0]);
- $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_PORT, $senderData[1]);
-
- // Is this a new peer?
- if ($this->isSenderNewPeer($packageData, $dataSetInstance)) {
- // "Insert" the data set
- $this->queryInsertDataSet($dataSetInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE));
- } else {
- // Update the data set
- $this->queryUpdateDataSet($dataSetInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE));
- }
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: Peer ' . $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . ' has been registered/updated with state ' . $stateInstance->getStateName());
- }
-
- /**
- * Purges old entries of given socket resource. We use the IP address from that resource.
- *
- * @param $socketResource A valid socket resource
- * @return void
- * @throws InvalidSocketException If the socket resource was invalid
- * @todo Unfinished area
- */
- public function purgeOldEntriesBySocketResource ($socketResource) {
- // Get peer name
- if (!@socket_getpeername($socketResource, $peerName, $peerPort)) {
- // Get last error
- $lastError = socket_last_error($socketResource);
-
- // Doesn't work!
- throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: peerName=' . $peerName . ',peerPort=' . $peerPort . ' - UNFINISHED!');
- }
-
- /**
- * 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 Valid package data array
- * @return $isSamePeerState Whether the peer's state is the same
- */
- public function isSamePeerState (ConnectionHelper $helperInstance, array $packageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: State ' . $helperInstance->getPrintableState() . ' needs to be checked it has changed ...');
-
- // Now get the search instance from given package data
- $searchInstance = $this->getSenderSearchInstanceFromPackageData($packageData);
-
- // With this search instance query the database for the peer and get a result instance
- $resultInstance = $this->doSelectByCriteria($searchInstance);
-
- // Do we have an entry? This should always the case
- assert($resultInstance->next());
-
- // Yes, so get the current (=first) entry from it
- $rowData = $resultInstance->current();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: rowData[' . gettype($rowData) . ']=' . print_r($rowData, TRUE));
-
- // Assert on important elements
- assert(isset($rowData[self::DB_COLUMN_PEER_STATE]));
-
- // Now just compare it with given state from helper instance
- $isSamePeerState = ($rowData[self::DB_COLUMN_PEER_STATE] == $helperInstance->getPrintableState());
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: state in database: ' . $rowData[self::DB_COLUMN_PEER_STATE] . ', new state: ' . $helperInstance->getPrintableState() . ',isSamePeerState=' . intval($isSamePeerState));
-
- // Return it
- return $isSamePeerState;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? decoder class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Decoder extends BaseDecoder implements Decodeable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $decoderInstance An instance of a Decodeable class
- */
- public final static function create???Decoder () {
- // Get new instance
- $decoderInstance = new ???Decoder();
-
- // Return the prepared instance
- return $decoderInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general Decoder class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseDecoder extends BaseHubSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Package decoder class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageDecoder extends BaseDecoder implements Decodeable, Registerable {
- /**
- * Name for stacker for received packages
- */
- const STACKER_NAME_DECODED_PACKAGE = 'decoded_package';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $handlerInstance An instance of a HandleableChunks class
- * @return $decoderInstance An instance of a Decodeable class
- */
- public final static function createPackageDecoder (HandleableChunks $handlerInstance) {
- // Get new instance
- $decoderInstance = new PackageDecoder();
-
- // Init stacker for received packages
- $handlerInstance->getStackInstance()->initStack(self::STACKER_NAME_DECODED_PACKAGE);
-
- // Set the handler instance here
- $decoderInstance->setHandlerInstance($handlerInstance);
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // And set it in this decoder
- $decoderInstance->setPackageInstance($packageInstance);
-
- // Return the prepared instance
- return $decoderInstance;
- }
-
- /**
- * Checks whether the assoziated stacker for raw package data has some entries left
- *
- * @return $unhandledDataLeft Whether some unhandled raw package data is left
- */
- public function ifUnhandledRawPackageDataLeft () {
- // Check it
- $unhandledDataLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA));
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: unhandledDataLeft=' . intval($unhandledDataLeft));
- return $unhandledDataLeft;
- }
-
- /**
- * Handles raw package data by decoding it
- *
- * @return void
- */
- public function handleRawPackageData () {
- // Assert on it to make sure the next popNamed() call won't throw an exception
- assert($this->ifUnhandledRawPackageDataLeft());
-
- // "Pop" the next raw package content
- $rawPackageContent = $this->getHandlerInstance()->getStackInstance()->popNamed(ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: Got ' . strlen($rawPackageContent) . ' bytes from stack ' . ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA . ', decoding it ...');
-
- // "Decode" the raw package content by using the NetworkPackage instance
- $decodedData = $this->getPackageInstance()->decodeRawContent($rawPackageContent);
-
- // Some checks
- assert(
- (is_array($decodedData)) &&
- (isset($decodedData[NetworkPackage::PACKAGE_DATA_SENDER])) &&
- (isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) &&
- (isset($decodedData[NetworkPackage::PACKAGE_DATA_CONTENT])) &&
- (isset($decodedData[NetworkPackage::PACKAGE_DATA_STATUS]))
- );
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: decodedData(' . count($decodedData) . ')=' . print_r($decodedData, TRUE));
-
- // Next get a recipient-discovery instance
- $discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
-
- // ... then disover all recipient (might be only one), this package may shall be forwarded
- $discoveryInstance->discoverRawRecipients($decodedData);
-
- // Check for 'recipient' field (the 'sender' field and others are ignored here)
- if ($discoveryInstance->isRecipientListEmpty()) {
- // The recipient is this node so next stack it on 'decoded_package'
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: Pushing ' . strlen($decodedData) . ' bytes to stack ' . self::STACKER_NAME_DECODED_PACKAGE . ' ...');
- $this->getHandlerInstance()->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_PACKAGE, $decodedData);
- } else {
- // Forward the package to the next node
- $this->getPackageInstance()->forwardRawPackage($decodedData);
- }
- }
-
- /**
- * Checks whether decoded packages have arrived (for this peer)
- *
- * @return $ifRawPackagesLeft Whether decoded packages have arrived
- */
- public function ifDeocedPackagesLeft () {
- // Check it ...
- $ifRawPackagesLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_PACKAGE));
-
- // ... return it
- return $ifRawPackagesLeft;
- }
-
- /**
- * Handles received decoded packages internally (recipient is this node)
- *
- * @return void
- */
- public function handleDecodedPackage () {
- // Assert on amount
- assert($this->ifDeocedPackagesLeft());
-
- // Get the next entry (assoziative array)
- $decodedData = $this->getHandlerInstance()->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_PACKAGE);
-
- // Handle it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-DECODER[' . __METHOD__ . ':' . __LINE__ . ']: decodedData(' . count($decodedData) . ')=' . print_r($decodedData, TRUE));
- $this->getPackageInstance()->handleRawData($decodedData);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? DHT facade class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???DhtFacade extends BaseDht implements Distributable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $dhtInstance An instance of a Distributable class
- */
- public final static function create??? () {
- // Get new instance
- $dhtInstance = new ???DhtFacade();
-
- // Return the prepared instance
- return $dhtInstance;
- }
-
- /**
- * Registers/updates an entry in the DHT with given data from $dhtData
- * array. Different DHT implemtations may handle this differently as they
- * may enrich the data with more meta data.
- *
- * @param $dhtData A valid array with DHT-related data (e.g. node/peer data)
- * @return void
- * @todo 0% done
- */
- protected function insertDataIntoDht (array $dhtData) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general DHT class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
- */
-abstract class BaseDht extends BaseHubSystem implements Distributable {
- /**
- * "Cached" instance of a publish helper
- */
- private $publishHelperInstance = NULL;
-
- /**
- * Stacker name for "INSERT" node data
- */
- const STACKER_NAME_INSERT_NODE = 'dht_insert_node';
- const STACKER_NAME_PENDING_PUBLISHING = 'dht_pending_publish';
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Get a stacker instance for this DHT
- $stackInstance = ObjectFactory::createObjectByConfiguredName('dht_stacker_class');
-
- // Set it in this class
- $this->setStackInstance($stackInstance);
-
- // Init all stackers
- $this->initStacks();
-
- // Get the state factory and create the initial state.
- DhtStateFactory::createDhtStateInstanceByName('init', $this);
- }
-
- /**
- * Initializes all stackers
- *
- * @return void
- */
- private function initStacks () {
- // Initialize all stacker
- $this->getStackInstance()->initStacks(array(
- self::STACKER_NAME_INSERT_NODE,
- self::STACKER_NAME_PENDING_PUBLISHING,
- ));
- }
-
- /**
- * Registers/updates an entry in the DHT with given data from $dhtData
- * array. Different DHT implemtations may handle this differently as they
- * may enrich the data with more meta data.
- *
- * @param $dhtData A valid array with DHT-related data (e.g. node/peer data)
- * @return void
- */
- protected abstract function insertDataIntoDht (array $dhtData);
-
- /**
- * Updates/refreshes DHT data (e.g. status).
- *
- * @return void
- * @todo Find more to do here
- */
- public function updateDhtData () {
- // Set some dummy configuration entries, e.g. dht_status
- $this->getConfigInstance()->setConfigEntry('dht_status', $this->getStateInstance()->getStateName());
- }
-
- /**
- * Checks whether there are entries in "INSERT" node data stack
- *
- * @return $isPending Whether there are pending entries
- */
- public function ifInsertNodeDataPending () {
- // Determine it if it is not empty
- $isPending = ($this->getStackInstance()->isStackEmpty(self::STACKER_NAME_INSERT_NODE) === FALSE);
-
- // Return status
- return $isPending;
- }
-
- /**
- * Inserts a single entry of node data into the DHT
- *
- * @return void
- */
- public function insertSingleNodeData () {
- // Get next node data from stack
- $nodeData = $this->getStackInstance()->popNamed(self::STACKER_NAME_INSERT_NODE);
-
- // Make sure $nodeData is really an array and has at least one entry
- assert((is_array($nodeData)) && (count($nodeData) > 0));
-
- // Insert the data
- $this->insertDataIntoDht($nodeData);
- }
-
- /**
- * Checks whether there are unpublished entries
- *
- * @return $hasUnpublished Whether there are unpublished entries
- * @todo Add minimum/maximum age limitations
- */
- public function hasUnpublishedEntries () {
- // Call method on database wrapper
- $hasUnpublished = $this->getWrapperInstance()->hasUnpublishedEntries();
-
- // Return it
- return $hasUnpublished;
- }
-
- /**
- * Initializes publication of DHT entries. This does only prepare
- * publication. The next step is to pickup such prepared entries and publish
- * them by uploading to other (recently appeared) DHT members.
- *
- * @return void
- */
- public function initEntryPublication () {
- // Call method on database wrapper
- $this->getWrapperInstance()->initEntryPublication();
-
- // Get result instance
- $resultInstance = $this->getWrapperInstance()->getUnpublishedEntriesInstance();
-
- // Make sure the result instance is valid
- assert($resultInstance instanceof SearchableResult);
- assert($resultInstance->valid());
-
- // "Walk" through all entries
- while ($resultInstance->next()) {
- // Get current entry
- $current = $resultInstance->current();
-
- // Make sure only valid entries pass
- // @TODO Maybe add more small checks?
- assert(is_array($current));
-
- // ... and push it to the next stack
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] Pushing entry with ' . count($current) . ' elements to stack ' . self::STACKER_NAME_PENDING_PUBLISHING . ' ...');
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_PENDING_PUBLISHING, $current);
- } // END - while
- }
-
- /**
- * Checks whether there are entries pending publication
- *
- * @return $isPending Whether there are entries pending publication
- */
- public function hasEntriesPendingPublication () {
- // Determine it if it is not empty
- $isPending = ($this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PENDING_PUBLISHING) === FALSE);
-
- // Return status
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] isPending=' . intval($isPending));
- return $isPending;
- }
-
- /**
- * Whether this DHT's state is 'booting'
- *
- * @return $isBooting Whether this DHT is currently booting
- */
- public function ifDhtIsBooting () {
- // Call state instance
- $isBooting = $this->getStateInstance()->ifDhtIsBooting();
-
- // Return status
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] isBooting=' . intval($isBooting));
- return $isBooting;
- }
-
- /**
- * Publishes next entry found in stack. This method shall also update the
- * corresponding dabase entry.
- *
- * @return void
- * @todo Find out if loadDescriptorXml() can be called only once to avoid a lot methods working.
- */
- public function publishEntry () {
- // This test must not fail
- assert($this->hasEntriesPendingPublication());
-
- // Is there an instance?
- if (!$this->publishHelperInstance instanceof HelpableDht) {
- // Get a helper instance
- $this->publishHelperInstance = ObjectFactory::createObjectByConfiguredName('dht_publish_entry_helper_class');
- } // END - if
-
- // Load the announcement descriptor
- $this->publishHelperInstance->loadDescriptorXml($this);
-
- // "Pop" next entry
- $entry = $this->getStackInstance()->popNamed(self::STACKER_NAME_PENDING_PUBLISHING);
-
- // Some sanity-checks
- assert(is_array($entry));
-
- // Remove any non-public data the database layer desires
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT[' . __METHOD__ . ':' . __LINE__ . ']: Calling this->getWrapperInstance()->removeNonPublicDataFromArray(data) ...');
- $entry = $this->getWrapperInstance()->removeNonPublicDataFromArray($entry);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT[' . __METHOD__ . ':' . __LINE__ . ']: entry[]=' . gettype($entry));
-
- // Some sanity-checks again
- assert(is_array($entry));
-
- // Assign multiple variables
- $this->publishHelperInstance->getTemplateInstance()->assignMultipleVariables($entry);
-
- // "Publish" the descriptor by sending it to the bootstrap/list nodes
- $this->publishHelperInstance->sendPackage($this);
- }
-
- /**
- * Whether the DHT has fully bootstrapped (after state 'booting')
- *
- * @return $isFullyBooted Whether the DHT is fully booted
- * @todo 0% done
- */
- public function hasFullyBootstrapped () {
- // Get state and check it
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Enable DHT bootstrap request acceptance for local node
- *
- * @return void
- * @todo Switch flag 'accept_bootstrap'
- */
- public function enableAcceptDhtBootstrap () {
- // Call method on database wrapper
- $this->getWrapperInstance()->enableAcceptDhtBootstrap();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Node DHT facade class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $dhtInstance An instance of a Distributable class
- */
- public final static function createNodeDhtFacade () {
- // Get new instance
- $dhtInstance = new NodeDhtFacade();
-
- // Get a database wrapper instance
- $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_dht_db_wrapper_class');
-
- // Set it in this class
- $dhtInstance->setWrapperInstance($wrapperInstance);
-
- // Return the prepared instance
- return $dhtInstance;
- }
-
- /**
- * Registers/updates an entry in the DHT with given data from $dhtData
- * array. Different DHT implemtations may handle this differently as they
- * may enrich the data with more meta data.
- *
- * @param $dhtData A valid array with DHT-related data (e.g. node/peer data)
- * @return void
- * @todo Does this data need to be enriched with more meta data?
- */
- protected function insertDataIntoDht (array $dhtData) {
- // Check if there is already an entry for given node_id
- if ($this->getWrapperInstance()->isNodeRegistered($dhtData)) {
- /*
- * Update existing record. Please note that this step is not secure
- * (e.g. DHT poisoning) it would be good to implement some checks if
- * the both node owner trust each other (see sub-project 'DSHT').
- */
- $this->getWrapperInstance()->updateNode($dhtData);
- } else {
- /*
- * Inserts given node data into the DHT. As above, this step does
- * currently not perform any security checks.
- */
- $this->getWrapperInstance()->registerNode($dhtData);
- }
- }
-
- /**
- * Initializes the distributed hash table (DHT)
- *
- * @return void
- */
- public function initDht () {
- // Is the local node registered?
- if ($this->getWrapperInstance()->isLocalNodeRegistered()) {
- // Then only update session id
- $this->getWrapperInstance()->updateLocalNode();
- } else {
- // No, so register it
- $this->getWrapperInstance()->registerLocalNode();
- }
-
- // Change state
- $this->getStateInstance()->dhtHasInitialized();
- }
-
- /**
- * Bootstraps the DHT by sending out a message to all available nodes
- * (including itself). This step helps the node to get to know more nodes
- * which can be queried later for object distribution.
- *
- * @return void
- */
- public function bootstrapDht () {
- // Get a helper instance
- $helperInstance = ObjectFactory::createObjectByConfiguredName('dht_bootstrap_helper_class');
-
- // Load the announcement descriptor
- $helperInstance->loadDescriptorXml($this);
-
- // Compile all variables
- $helperInstance->getTemplateInstance()->compileConfigInVariables();
-
- // "Publish" the descriptor by sending it to the bootstrap/list nodes
- $helperInstance->sendPackage($this);
-
- // Change state
- $this->getStateInstance()->dhtIsBooting();
- }
-
- /**
- * Finds a node locally by given session id
- *
- * @param $sessionId Session id to lookup
- * @return $nodeData Node-data array
- */
- public function findNodeLocalBySessionId ($sessionId) {
- // Default is empty data array
- $nodeData = array();
-
- /*
- * Call the wrapper to do the job and get back a result instance. There
- * will come back zero or one entry from the wrapper.
- */
- $resultInstance = $this->getWrapperInstance()->findNodeLocalBySessionId($sessionId);
-
- // Make sure the result instance is valid
- assert($resultInstance instanceof SearchableResult);
-
- // Is the next entry valid?
- if (($resultInstance->valid()) && ($resultInstance->next())) {
- /*
- * Then load the first entry (more entries are being ignored and
- * should not happen).
- */
- $nodeData = $resultInstance->current();
- } // END - if
-
- // Return node data
- return $nodeData;
- }
-
- /**
- * Registers an other node with this node by given message data. The
- * following data must always be present:
- *
- * - session-id (for finding the node's record together with below data)
- * - external-address (hostname or IP number)
- * - listen-port (TCP/UDP listen port for inbound connections)
- *
- * @param $messageArray An array with all minimum message data
- * @param $handlerInstance An instance of a HandleableDataSet class
- * @param $forceUpdate Optionally force update, don't register (default: register if not found)
- * @return void
- * @throws NodeSessionIdVerficationException If the node was not found and update is forced
- */
- public function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, $forceUpdate = FALSE) {
- // Get a search criteria class
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE) . ',handlerInstance=' . $handlerInstance->__toString() . ',forceUpdate=' . intval($forceUpdate) . ',count(getSearchData())=' . count($handlerInstance->getSearchData()));
-
- // Search for the node's session id and external address/hostname + TCP/UDP listen port
- foreach ($handlerInstance->getSearchData() as $key) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getPrintableState() . ',key=' . $key);
-
- // Is it there?
- assert(isset($messageData[$key]));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData[' . $key . ']=' . $messageData[$key]);
-
- // Add criteria
- $searchInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
- } // END - foreach
-
- // Only one entry is fine
- $searchInstance->setLimit(1);
-
- // Run the query
- $resultInstance = $this->getWrapperInstance()->doSelectByCriteria($searchInstance);
-
- // Make sure the result instance is valid
- assert($resultInstance instanceof SearchableResult);
-
- // Is there already an entry?
- if ($resultInstance->valid()) {
- // Entry found, so update it
- $this->getWrapperInstance()->updateNodeByMessageData($messageData, $handlerInstance, $searchInstance);
- } elseif ($forceUpdate === FALSE) {
- // Nothing found, so register it
- $this->getWrapperInstance()->registerNodeByMessageData($messageData, $handlerInstance);
- } else {
- /*
- * Do not register non-existent nodes here. This is maybe fatal,
- * caused by "stolen" session id and/or not matching address.
- */
- throw new NodeSessionIdVerficationException(array($this, $messageData), BaseHubSystem::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING);
- }
-
- // Save last exception
- $handlerInstance->setLastException($this->getWrapperInstance()->getLastException());
- }
-
- /**
- * Queries the local DHT data(base) for a node list with all supported
- * object types except the node by given session id.
- *
- * @param $messageData An array with message data from a node_list request
- * @param $handlerInstance An instance of a HandleableDataSet class
- * @param $excludeKey Array key which should be excluded
- * @param $andKey Array of $separator-separated list of elements which all must match
- * @param $separator Sepator char (1st parameter for explode() call)
- * @return $nodeList An array with all found nodes
- */
- public function queryLocalNodeListExceptByMessageData (array $messageData, HandleableDataSet $handlerInstance, $excludeKey, $andKey, $separator) {
- // Make sure both keys are there
- assert((isset($messageData[$excludeKey])) && (isset($messageData[$andKey])));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE));
-
- // Get a search criteria class
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Add all keys
- foreach (explode($separator, $messageData[$andKey]) as $criteria) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: andKey=' . $andKey . ',criteria=' . $criteria);
-
- // Add it and leave any 'my-' prefix out
- $searchInstance->addChoiceCriteria(str_replace('my-', '', $andKey), $criteria);
- } // END - foreach
-
- // Add exclusion key
- $searchInstance->addExcludeCriteria(str_replace('my-', '', $excludeKey), $messageData[$excludeKey]);
-
- // Only X entries are fine
- $searchInstance->setLimit($this->getConfigInstance()->getConfigEntry('node_dht_list_limit'));
-
- // Run the query
- $resultInstance = $this->getWrapperInstance()->doSelectByCriteria($searchInstance);
-
- // Make sure the result instance is valid
- assert($resultInstance instanceof SearchableResult);
- assert($resultInstance->valid());
-
- // Init array
- $nodeList = array();
-
- // Get node list
- while ($resultInstance->next()) {
- // Get current element (it should be an array, and have at least 1 entry)
- $current = $resultInstance->current();
- assert(is_array($current));
- assert(count($current) > 0);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: current(' . count($current) . ')[' . gettype($current) . ']=' . print_r($current, TRUE));
-
- /*
- * Remove some keys as they should not be published.
- */
- unset($current[$this->getWrapperInstance()->getIndexKey()]);
-
- // Add this entry
- array_push($nodeList, $current);
- } // END - while
-
- // Save last exception
- $handlerInstance->setLastException($this->getWrapperInstance()->getLastException());
-
- // Return node list (array)
- return $nodeList;
- }
-
- /**
- * Inserts given node list array (from earlier database result produced by
- * an other node) into the DHT. This array origins from above method
- * queryLocalNodeListExceptByMessageData().
- *
- * @param $nodeList An array from an earlier database result instance
- * @return void
- */
- public function insertNodeList (array $nodeList) {
- // If no node is in the list (array), skip the rest of this method
- if (count($nodeList) == 0) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: No node record has been returned.');
-
- // Abort here
- return;
- } // END - if
-
- // Put them all into a stack
- foreach ($nodeList as $nodeData) {
- // Insert all entries
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_INSERT_NODE, $nodeData);
- } // END - foreach
- }
-
- /**
- * Find recipients for given package data
- *
- * @param $packageData An array of valid package data
- * @return $recipients An indexed array with DHT recipients
- */
- public function findRecipientsByPackageData (array $packageData) {
- // Query get a result instance back from DHT database wrapper.
- $resultInstance = $this->getWrapperInstance()->getResultFromExcludedSender($packageData);
-
- // Make sure the result instance is valid
- assert($resultInstance instanceof SearchableResult);
-
- // No entries found?
- if (!$resultInstance->valid()) {
- // Then skip below loop
- return array();
- } // END - if
-
- // Init array
- $recipients = array();
-
- // Search for all recipients
- while ($resultInstance->next()) {
- // Get current entry
- $current = $resultInstance->current();
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __METHOD__ . ':' . __LINE__ . ']: current=' . print_r($current, TRUE));
-
- // Add instance to recipient list
- array_push($recipients, $current);
- } // END - while
-
- // Return filled array
- return $recipients;
- }
-
- /**
- * Finds DHT recipients by given key/value pair
- *
- * @param $key Key to search for
- * @param $value Value to check on found key
- * @return $recipiens Array with DHT recipients from given key/value pair
- */
- public function findRecipientsByKey ($key, $value) {
- // Look for all suitable nodes
- $resultInstance = $this->getWrapperInstance()->getResultFromKeyValue($key, $value);
-
- // Make sure the result instance is valid
- assert($resultInstance instanceof SearchableResult);
- assert($resultInstance->valid());
-
- // Init array
- $recipients = array();
-
- // "Walk" through all entries
- while ($resultInstance->next()) {
- // Get current entry
- $current = $resultInstance->current();
-
- // Add instance to recipient list
- array_push($recipients, $current);
- } // END - while
-
- // Return filled array
- return $recipients;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A !!! discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 !!!Discovery extends BaseNodeDiscovery implements Discoverable,,,, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Create an instance of this class
- *
- * @return $discoveryInstance An instance of this discovery class
- */
- public static final function create!!!Discovery () {
- // Get an instance of this class
- $discoveryInstance = new !!!Discovery();
-
- // Return the prepared instance
- return $discoveryInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general node discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseNodeDiscovery extends BaseDiscovery implements Discoverable {
- /**
- * Protected constructor
- *
- * @param $className Real class name
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A UniversalNodeLocator discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements DiscoverableUniversalNodeLocator, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Create an instance of this class
- *
- * @return $discoveryInstance An instance of this discovery class
- */
- public static final function createUniversalNodeLocatorDiscovery () {
- // Get an instance of this class
- $discoveryInstance = new UniversalNodeLocatorDiscovery();
-
- // Return the prepared instance
- return $discoveryInstance;
- }
-
- /**
- * "Discovers" an instance of a LocateableNode class for given NodeHelper class
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return $unlInstance An instance of a LocateableNode class
- */
- public function discoverUniversalNodeLocatorByNode (NodeHelper $nodeInstance) {
- /*
- * First get an instance from the configured hub communication protocol
- * type (which is mostly TCP, so you get a TcpProtocolResolver here).
- */
- $resolverInstance = ProtocolResolverFactory::createResolverFromConfiguredProtocol();
-
- // Then resolve the node instance into an UNL instance
- $unlInstance = $resolverInstance->resolveUniversalNodeLocatorFromNodeHelper($nodeInstance);
-
- // ... and return it
- return $unlInstance;
- }
-
- /**
- * "Discovers" the full universal node locator for given configuration entry
- * which should represent the address part of the UNL. In case of an IP
- * address, this *must not* include the port number as this is being found
- * out for you.
- *
- * Valid values for $configKey: internal,external
- *
- * @param $configKey Key for address to get (valid: internal,external)
- * @return $unl Universal node locator
- */
- public function discoverUniversalNodeLocatorByConfiguredAddress ($configKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('UNL-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']:configKey=' . $configKey . ' - CALLED!');
-
- // Is there cache?
- if (!isset($GLOBALS[__METHOD__][$configKey])) {
- // Validate config key
- assert(($configKey == 'internal') || ($configKey == 'external'));
-
- /*
- * First get an instance from the configured hub communication protocol
- * type (which is mostly TCP, so you get a TcpProtocolResolver here).
- */
- $resolverInstance = ProtocolResolverFactory::createResolverFromConfiguredProtocol();
-
- // Get back the full UNL
- $GLOBALS[__METHOD__][$configKey] = $resolverInstance->resolveUniversalNodeLocatorFromConfigKey($configKey);
- } // END - if
-
- // Return cached value
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('UNL-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']:configKey=' . $configKey . ',unl=' . $GLOBALS[__METHOD__][$configKey] . ' - EXIT!');
- return $GLOBALS[__METHOD__][$configKey];
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Protocol discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtocol, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Create an instance of this class
- *
- * @return $discoveryInstance An instance of this discovery class
- */
- public static final function createProtocolDiscovery () {
- // Get an instance of this class
- $discoveryInstance = new ProtocolDiscovery();
-
- // Return the prepared instance
- return $discoveryInstance;
- }
-
- /**
- * Determines the protoctol name
- *
- * @param $packageData Valid package data
- * @return $protocolInstance An instance of a HandleableProtocol class
- */
- public static final function determineProtocolByPackageData (array $packageData) {
- // First we need a tags instance
- $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
-
- /*
- * We need to decide here which socket (TCP or UDP) should be used for
- * the actual data transmission. In this process we will find out if
- * the recipient of this package has already a known (registered) socket
- * and if so we can re-use it. If there is no socket registered, we try
- * to make a new connection to the given Universal Node Locator.
- */
- $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
-
- // Return it
- return $protocolInstance;
- }
-
- /**
- * "Discovers" the protocol type from given raw package data. This is done
- * by looking at the 'recipient' field and extract the first part from it.
- *
- * @param $packageData Raw package data
- * @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
- */
- public static final function discoverProtocolByPackageData (array $packageData) {
- //* DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
-
- /*
- * "Explode" the 'recipient' array element into a new one, giving at
- * least two entries: protocol://address
- */
- $recipient = explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
- // At least 2 entries must be found
- assert(count($recipient) >= 2);
-
- // Now get the first part (protocol type) and make all lower-case
- $protocolType = strtolower($recipient[0]);
-
- // Return it
- // @TODO Add some validation here???
- return $protocolType;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A !!! recipient discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 !!!RecipientDiscovery extends BaseRecipientDiscovery implements Discoverable,,,Recipient, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Create an instance of this class
- *
- * @return $discoveryInstance An instance of this discovery class
- */
- public static final function create!!!Discovery () {
- // Get an instance of this class
- $discoveryInstance = new !!!Discovery();
-
- // Return the prepared instance
- return $discoveryInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A PackageRecipient discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseRecipientDiscovery extends BaseNodeDiscovery implements DiscoverableRecipient {
- /**
- * Protected constructor
- *
- * @param $className Real class name
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- /*
- * Get recipients list instance and set it here for all discovery
- * implementations.
- */
- $listInstance = RecipientListFactory::createRecipientListInstance();
- $this->setListInstance($listInstance);
- }
-
- /**
- * "Getter" for recipient iterator
- *
- * @return$iteratorInstance An instance of a Iterateable object
- */
- public final function getIterator () {
- // Get iterator from it
- $iteratorInstance = $this->getListInstance()->getIterator();
-
- // Return it
- return $iteratorInstance;
- }
-
- /**
- * Clears all recipients for e.g. another package to deliver. This method
- * simply clears the inner list instance.
- *
- * @return void
- */
- public final function clearRecipients () {
- // Clear the list
- $this->getListInstance()->clearList();
- }
-
- /**
- * Checks whether the recipient list is empty
- *
- * @return $isEmpty Whether the recipient list is empty
- */
- public final function isRecipientListEmpty () {
- // Check it ...
- $isEmpty = ($this->getListInstance()->count() == 0);
-
- // Return it
- return $isEmpty;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A DhtRecipient discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableDhtRecipient, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Create an instance of this class
- *
- * @return $discoveryInstance An instance of this discovery class
- */
- public static final function createDhtRecipientDiscovery () {
- // Get an instance of this class
- $discoveryInstance = new DhtRecipientDiscovery();
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set it here
- $discoveryInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $discoveryInstance;
- }
-
- /**
- * Resolves one or more recipients for a DHT transfer by given package data.
- *
- * @param $packageData Valid package data array
- * @return $recipients An indexed array with DHT recipients
- */
- public function resolveRecipientsByPackageData (array $packageData) {
- // Use facade to get recipients back
- $recipients = $this->getDhtInstance()->findRecipientsByPackageData($packageData);
-
- // Return it
- return $recipients;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A PackageRecipient discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableNodeRecipient, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Create an instance of this class
- *
- * @return $discoveryInstance An instance of this discovery class
- */
- public static final function createPackageRecipientDiscovery () {
- // Get an instance of this class
- $discoveryInstance = new PackageRecipientDiscovery();
-
- // Return the prepared instance
- return $discoveryInstance;
- }
-
- /**
- * Tries to discover all recipients for given package data
- *
- * @param $packageData Raw package data array
- * @return void
- */
- public function discoverRecipients (array $packageData) {
- // This must be available
- //* DEBUG: */ print $this->__toString() . ': packageData=' . print_r($packageData, TRUE);
- assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
-
- // First try out the direct recipient (session id)
- try {
- // Get instance (should not break)
- $recipientInstance = ObjectFactory::createObjectByConfiguredName('direct_recipient_class');
-
- // Try to solve it
- $recipientInstance->resolveRecipient($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance(), $packageData);
- } catch (FrameworkException $e) {
- // Didn't work, so try the non-generic, depending recipient field itself (this may fail)
- try {
- // Try to find the right class
- $recipientInstance = ObjectFactory::createObjectByConfiguredName(strtolower($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) . '_recipient_class');
-
- // And try to solve again
- $recipientInstance->resolveRecipient($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance(), $packageData);
- } catch (FrameworkException $e) {
- // Could not find class, what ever failed
- $this->debugInstance($e->getMessage());
- }
- }
- }
-
- /**
- * Tries to discover all recipients by given decoded package data.
- *
- * @param $decodedData Raw raw package data array
- * @return void
- * @todo Add some validation of recipient field, e.g. an Universal Node Locator is found
- * @todo Enrich both messages with recipient data
- */
- public function discoverRawRecipients (array $decodedData) {
- // This must be available
- assert(isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
-
- // First clear all recipients
- $this->clearRecipients();
-
- // Get a protocol handler back from decoded data
- $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($decodedData);
-
- // Is the 'recipient' field same as this peer's IP?
- if ($handlerInstance->isOwnAddress($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
- /*
- * Is same as own external address + TCP/UDP listen port or
- * internal address, don't do anything here so other classes found
- * an empty recipient list for internal (own) handling of the
- * original content.
- */
-
- // Debug output (may flood)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' matches own ip (external=' . HubTools::determineOwnExternalAddress() . ' or internal=' . HubTools::determineOwnInternalAddress() . ')');
- } else {
- // Debug output (may flood)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' is different than own external address (' . HubTools::determineOwnExternalAddress() . ') nor internal address (' . HubTools::determineOwnInternalAddress() . '), need to forward (not yet implemented)!');
-
- // This package is to be delivered to someone else, so add it
- // @TODO Unfinished: $this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
- }
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A socket discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageSocketDiscovery extends BaseRecipientDiscovery implements DiscoverableSocket, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Create an instance of this class
- *
- * @return $discoveryInstance An instance of this discovery class
- */
- public static final function createPackageSocketDiscovery () {
- // Get an instance of this class
- $discoveryInstance = new PackageSocketDiscovery();
-
- // Output debug message
- self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Initialized.');
-
- // Return the prepared instance
- return $discoveryInstance;
- }
-
- /**
- * Tries to dicover the right listener instance
- *
- * @param $protocolInstance An instance of a HandleableProtocol class
- * @param $packageData Raw package data
- * @return $listenerInstance An instance of a Listenable instance or null
- */
- public function discoverListenerInstance (HandleableProtocol $protocolInstance, array $packageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolInstance=' . $protocolInstance->__toString() . ' - CALLED!');
-
- /*
- * Get the listener pool instance, we need to lookup the matching
- * listener->poolInstance chain there.
- */
- $poolInstance = NodeObjectFactory::createNodeInstance()->getListenerPoolInstance();
-
- // Init listener instance
- $listenerInstance = NULL;
-
- // Get handler name
- $protocolName = $protocolInstance->getProtocolName();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ',poolEntriesInstance=' . $poolInstance->getPoolEntriesInstance()->__toString());
-
- /*
- * Now we need to choose again. It is whether we are speaking with a hub
- * or with a client. So just handle it over to all listeners in this
- * pool.
- */
- foreach ($poolInstance->getPoolEntriesInstance()->getArrayFromList($protocolName) as $listenerInstance) {
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ',listenerInstance[' . gettype($listenerInstance) . ']=' . $listenerInstance);
-
- // Make sure the instance is valid
- assert($listenerInstance instanceof Listenable);
-
- // Does the listener want that package?
- if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) {
- // This listener likes our package data, so abort here
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Listener is accepting package data.');
- break;
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Listener is NOT accepting package data.');
- } // END - foreach
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: listenerInstance=' . $listenerInstance->__toString());
-
- // Return it
- return $listenerInstance;
- }
-
- /**
- * Tries to discover the right socket for given package data and returns a
- * matching socket resource for that protocol.
- *
- * @param $packageData Raw package data array
- * @param $connectionType Type of connection, can be 'incoming' or 'outgoing', *NEVER* 'server'!
- * @return $socketResource A valid socket resource or FALSE if an error occured
- * @throws NoListGroupException If the procol group is not found in peer list
- * @throws NullPointerException If listenerInstance is NULL
- * @throws InvalidUnlException If the provided UNL cannot be validated by the protocol handler
- */
- public function discoverSocket (array $packageData, $connectionType) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: connectionType=' . $connectionType . ' - CALLED!');
-
- // Assert on type and recipient
- assert($connectionType != BaseConnectionHelper::CONNECTION_TYPE_SERVER);
- assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
-
- // Determine protocol instance
- $protocolInstance = ProtocolDiscovery::determineProtocolByPackageData($packageData);
-
- // Is it valid?
- assert($protocolInstance instanceof HandleableProtocol);
-
- // Does the UNL validate?
- if (!$protocolInstance->isValidUniversalNodeLocatorByPackageData($packageData)) {
- // Not valid, throw exception
- throw new InvalidUnlException(array($this, $protocolInstance, $packageData), BaseHubSystem::EXCEPTION_INVALID_UNL);
- } // END - if
-
- // Get the listener instance
- $listenerInstance = $this->discoverListenerInstance($protocolInstance, $packageData);
-
- // If there is no listener who wants to have that package, we simply drop it here
- if (is_null($listenerInstance)) {
- // Abort with no resource
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE));
-
- /*
- * Now we have the listener instance, we can determine the right
- * resource to continue. The first step is to get the attached pool
- * instance and pass over the whole package data to get the right
- * socket.
- */
- $socketResource = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData, $connectionType);
-
- // Debug message
- // @TODO FIXME: I don't like these abuse of variables, better strict types
- if (is_resource($socketResource)) {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',error=' . socket_strerror(socket_last_error($socketResource)) . ',packageData=' . print_r($packageData, TRUE));
- } else {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',packageData=' . print_r($packageData, TRUE));
- }
-
- // Is it FALSE, the recipient isn't known to us and we have no connection to it
- if (($socketResource === FALSE) || (!is_resource($socketResource)) || (socket_last_error($socketResource) > 0)) {
- // Try to create a new socket resource
- try {
- // Possibly noisy debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to establish a ' . strtoupper($protocolInstance) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
-
- // Get a socket resource from our factory (if succeeded)
- $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolInstance);
- } catch (SocketConnectionException $e) {
- // The connection fails of being established, so log it away
- self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Caught ' . $e->__toString() . ',message=' . $e->getMessage());
- }
- } // END - if
-
- // Try to resolve the socket resource
- try {
- // Get the helper instance from registry
- $helperInstance = Registry::getRegistry()->getInstance('connection');
-
- // Possibly noisy debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Going to resolve socket from peer state and given package data ...');
-
- // Resolve the peer's state (but ignore return value)
- PeerStateResolver::resolveStateByPackage($helperInstance, $packageData, $socketResource);
- } catch (InvalidSocketException $e) {
- // This cannot be fixed, so log it away
- self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Cannot discover socket resource for recipient ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ': ' . $e->getMessage());
-
- // Make any failed attempts to 'FALSE'
- $socketResource = FALSE;
- }
-
- // And return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: socketResource=' . $socketResource . ',packageData=' . print_r($packageData, TRUE));
- return $socketResource;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for network packages
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageFilterChainFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a filter chain by given tags array.
- *
- * @param $tags An array with tags from a package
- * @return $chainInstance An instance of a filter chain class
- */
- public static final function createChainByTagsArray (array $tags) {
- // Get a registry key from tags array, this does mostly call implode()
- $registryKey = Registry::getRegistryKeyFromArray('package_filter_chain', $tags);
-
- // Is the registry key there?
- if (Registry::getRegistry()->instanceExists($registryKey)) {
- // Yes, then use that instance
- $chainInstance = Registry::getRegistry()->getInstance($registryKey);
- } else {
- // Initialize a filter chain class
- $chainInstance = self::createObjectByConfiguredName('package_filter_chain_class');
-
- // "Walk" through all tags entries
- foreach ($tags as $tag) {
- /*
- * Now create a filter instance of this tag. This way all tags
- * got rudymentary verified, if an exception is coming here, it
- * simply means the tag is not valid. This however should be
- * handled some calls before this method is called.
- */
- $filterInstance = self::createObjectByConfiguredName('package_tag_' . $tag . '_filter');
-
- // Add this filter to the chain
- $chainInstance->addFilter($filterInstance);
- } // END - foreach
-
- // Add the finished chain to the registry
- Registry::getRegistry()->addInstance($registryKey, $chainInstance);
- }
-
- // Return the chain instance
- return $chainInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for chunk handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ChunkHandlerFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton (registry-based) chunk handler instance
- *
- * @return $handlerInstance An instance of a chunk handler class
- */
- public static final function createChunkHandlerInstance () {
- // If there is no handler?
- if (Registry::getRegistry()->instanceExists('chunk_handler')) {
- // Get handler from registry
- $handlerInstance = Registry::getRegistry()->getInstance('chunk_handler');
- } else {
- // Get the handler instance
- $handlerInstance = self::createObjectByConfiguredName('chunk_handler_class');
-
- // Add it to the registry
- Registry::getRegistry()->addInstance('chunk_handler', $handlerInstance);
- }
-
- // Return the instance
- return $handlerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A factory class for !!!
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Factory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton (registry-based) !!! instance
- *
- * @return $%%%Instance An instance of a !!! class
- */
- public static final function create???Instance () {
- // If there is no handler?
- if (Registry::getRegistry()->instanceExists('|||')) {
- // Get handler from registry
- $%%%Instance = Registry::getRegistry()->getInstance('|||');
- } else {
- // Get the handler instance
- $%%%Instance = self::createObjectByConfiguredName('|||_class');
-
- // Add it to the registry
- Registry::getRegistry()->addInstance('|||', $%%%Instance);
- }
-
- // Return the instance
- return $%%%Instance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for communicator
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014, 2015 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 CommunicatorFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton communicator instance. If no instance is found, it fill
- * be generated and stored in registry, else the communicator from the
- * registry will be returned.
- *
- * @param $configEntry A configuration entry naming the real class' name
- * @parasm $communicatorType Type of the communicator, can currently be 'node'
- * @return $communicatorInstance A communicator instance
- */
- public static final function createCommunicatorInstance ($configEntry, $communicatorType) {
- // If there is no communicator?
- if (Registry::getRegistry()->instanceExists($communicatorType . '_communicator')) {
- // Get communicator from registry
- $communicatorInstance = Registry::getRegistry()->getInstance($communicatorType . '_communicator');
- } else {
- // Get the communicator instance
- $communicatorInstance = self::createObjectByConfiguredName($configEntry);
-
- // Add it to the registry
- Registry::getRegistry()->addInstance($communicatorType . '_communicator', $communicatorInstance);
- }
-
- // Return the instance
- return $communicatorInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for Decodeable objects
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 DecoderFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton (registry-based) Decodeable instance
- *
- * @return $decoderInstance An instance of a Decodeable class
- */
- public static final function createPackageDecoderInstance () {
- // If there is no handler?
- if (Registry::getRegistry()->instanceExists('package_decoder')) {
- // Get handler from registry
- $decoderInstance = Registry::getRegistry()->getInstance('package_decoder');
- } else {
- // Get a chunk handler instance
- $handlerInstance = ChunkHandlerFactory::createChunkHandlerInstance();
-
- // Get the handler instance
- $decoderInstance = self::createObjectByConfiguredName('package_decoder_class', array($handlerInstance));
-
- // Add it to the registry
- Registry::getRegistry()->addInstance('package_decoder', $decoderInstance);
- }
-
- // Return the instance
- return $decoderInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for DHT objects
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtObjectFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton (registry-based) DHT object instance
- *
- * @param $prefix Prefix for DHT class name and registry key
- * @return $dhtInstance An instance of a DHT object class
- */
- public static final function createDhtInstance ($prefix) {
- // Set instance name
- $name = $prefix . '_dht';
-
- // If there is no handler?
- if (Registry::getRegistry()->instanceExists($name)) {
- // Get handler from registry
- $dhtInstance = Registry::getRegistry()->getInstance($name);
- } else {
- // Get the handler instance
- $dhtInstance = self::createObjectByConfiguredName($name . '_class');
-
- // Add it to the registry
- Registry::getRegistry()->addInstance($name, $dhtInstance);
- }
-
- // Return the instance
- return $dhtInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for package discovery
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageDiscoveryFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * 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.
- *
- * @return $discoveryInstance A package discovery instance
- */
- public static final function createPackageDiscoveryInstance () {
- // Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists('package_discovery')) {
- // Then use this instance
- $discoveryInstance = Registry::getRegistry()->getInstance('package_discovery');
- } else {
- // Create a new instance
- $discoveryInstance = self::createObjectByConfiguredName('package_recipient_discovery_class');
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance('package_discovery', $discoveryInstance);
- }
-
- // Return the instance
- return $discoveryInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A factory class for socket discovery
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 SocketDiscoveryFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton network socket 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.
- *
- * @return $discoveryInstance A socket discovery instance
- */
- public static final function createSocketDiscoveryInstance () {
- // Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists('socket_discovery')) {
- // Then use this instance
- $discoveryInstance = Registry::getRegistry()->getInstance('socket_discovery');
- } else {
- // Create a new instance
- $discoveryInstance = self::createObjectByConfiguredName('socket_discovery_class');
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance('socket_discovery', $discoveryInstance);
- }
-
- // Return the instance
- return $discoveryInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for message type handlers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 MessageTypeHandlerFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton message type handler instance. If an instance is
- * found in registry, it will be returned, else a new instance is created
- * and stored in the same registry entry.
- *
- * @param $messageType Message type to create an object from
- * @return $handlerInstance A message type handler instance
- */
- public static final function createMessageTypeHandlerInstance ($messageType) {
- // Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists('message_type_' . $messageType . '_handler')) {
- // Then use this instance
- $handlerInstance = Registry::getRegistry()->getInstance('message_type_' . $messageType . '_handler');
- } else {
- // Now prepare the tags instance
- $handlerInstance = self::createObjectByConfiguredName('message_type_' . $messageType . '_handler_class');
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance('message_type_' . $messageType . '_handler', $handlerInstance);
- }
-
- // Return the instance
- return $handlerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A factory class for protocol handlers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Unfinished stuff
- *
- * 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 ProtocolHandlerFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a protocol handler based on given protocol type. This is mostly 'tcp'.
- *
- * @param $protocolType Protocol type to create/return a protocol handler instance for
- * @return $handlerInstance A protocol handler instance
- */
- private static function createProtocolHandlerByType ($protocolType) {
- // Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists($protocolType . '_protocol_handler')) {
- // Then use this instance
- $handlerInstance = Registry::getRegistry()->getInstance($protocolType . '_protocol_handler');
- } else {
- // Now prepare the tags instance
- $handlerInstance = self::createObjectByConfiguredName($protocolType . '_protocol_handler_class');
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance($protocolType . '_protocol_handler', $handlerInstance);
- }
-
- // Return the instance
- return $handlerInstance;
- }
-
- /**
- * Returns a singleton protocol handler instance from given HubHelper
- * instance. If an instance is found in registry, it will be returned, else
- * a new instance is created and stored in the same registry entry.
- *
- * @param $helperInstance An instance of a HubHelper class
- * @return $handlerInstance A protocol handler instance
- */
- public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) {
- // Get the protocol type from given helper instance
- $protocolType = $helperInstance->determineProtocolType();
-
- // Call super factory method
- return self::createProtocolHandlerByType($protocolType);
- }
-
- /**
- * Creates an instance of a protocol handler from given (raw) package data
- *
- * @param $packageData An array with raw package data
- * @return $handlerInstance A protocol handler instance
- */
- public static final function createProtocolHandlerFromPackageData (array $packageData) {
- // "Discover" the protocol type
- $protocolType = ProtocolDiscovery::discoverProtocolByPackageData($packageData);
-
- // Call super factory method
- return self::createProtocolHandlerByType($protocolType);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for ShareableInfo
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ConnectionInfoFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton (registry-based) ShareableInfo instance
- *
- * @param $protocolName Name of protocol (e.g. 'tcp')
- * @param $type Connection type ('listener' or 'helper')
- * @return $infoInstance An instance of a ShareableInfo class
- */
- public static final function createConnectionInfoInstance ($protocolName, $type) {
- // Generate key
- $key = 'connection_info_' . $protocolName . '_' . $type;
-
- // If there is no info?
- if (Registry::getRegistry()->instanceExists($key)) {
- // Get info from registry
- $infoInstance = Registry::getRegistry()->getInstance($key);
- } else {
- // Get the info instance
- $infoInstance = self::createObjectByConfiguredName('connection_info_class');
-
- // Add it to the registry
- Registry::getRegistry()->addInstance($key, $infoInstance);
- }
-
- // Return the instance
- return $infoInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for recipient lists
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 RecipientListFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * 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.
- *
- * @return $listInstance A recipient list instance
- */
- public static final function createRecipientListInstance () {
- // Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists('recipient_list')) {
- // Then use this instance
- $listInstance = Registry::getRegistry()->getInstance('recipient_list');
- } else {
- // Create a new instance
- $listInstance = self::createObjectByConfiguredName('recipient_list_class');
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance('recipient_list', $listInstance);
- }
-
- // Return the instance
- return $listInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for nodes
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 NodeObjectFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton (registry-based) NodeHelper instance
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return $nodeInstance An instance of a NodeHelper class
- * @throws FactoryRequiredParameterException If not all parameters are set and no instance 'node' is set.
- */
- public static final function createNodeInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) {
- // Get new factory instance
- $factoryInstance = new NodeObjectFactory();
-
- // If there is no handler?
- if (Registry::getRegistry()->instanceExists('node')) {
- // Get handler from registry
- $nodeInstance = Registry::getRegistry()->getInstance('node');
- } elseif (($requestInstance instanceof Requestable) && ($responseInstance instanceof Responseable)) {
- // The default node-mode is from our configuration
- $nodeMode = $factoryInstance->getConfigInstance()->getConfigEntry('node_default_mode');
-
- // Is the node 'mode' parameter set?
- if ($requestInstance->isRequestElementSet('mode')) {
- // Then use this which overrides the config entry temporarily
- $nodeMode = $requestInstance->getRequestElement('mode');
- } else {
- // Set it for easier re-usage
- $requestInstance->setRequestElement('mode', $nodeMode);
- }
-
- // Now convert the node-mode in a class name
- $className = 'Hub' . $factoryInstance->convertToClassName($nodeMode) . 'Node';
-
- // Get the node instance
- $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
-
- // Get a registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Set the app instance
- $nodeInstance->setApplicationInstance($applicationInstance);
-
- // Add node-specific filters
- $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
-
- // Add it to the registry
- Registry::getRegistry()->addInstance('node', $nodeInstance);
- } else {
- // Throw an exception here
- throw new FactoryRequiredParameterException($factoryInstance, self::EXCEPTION_FACTORY_REQUIRE_PARAMETER);
- }
-
- // Return the instance
- return $nodeInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for package assembler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageAssemblerFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton assembler instance. If no instance is found, it fill
- * be generated and stored in registry, else the assembler from the
- * registry will be returned.
- *
- * @param $packageInstance An instance of a Receivable instance
- * @return $assemblerInstance An instance of a Assembler instance
- */
- public static final function createAssemblerInstance (Receivable $packageInstance) {
- // If there is no assembler?
- if (Registry::getRegistry()->instanceExists('package_assembler')) {
- // Get assembler from registry
- $assemblerInstance = Registry::getRegistry()->getInstance('package_assembler');
- } else {
- // Get the assembler instance
- $assemblerInstance = self::createObjectByConfiguredName('package_assembler_class', array($packageInstance));
-
- // Add it to the registry
- Registry::getRegistry()->addInstance('package_assembler', $assemblerInstance);
- }
-
- // Return the instance
- return $assemblerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A factory class for network packages
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NetworkPackageFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * 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.
- *
- * @return $packageInstance A network package instance
- */
- public static final function createNetworkPackageInstance () {
- // 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, ZLIB should be fine but we
- * keep it open here so you can experiment with the settings and don't
- * need to touch this code.
- */
- $compressorInstance = self::createObjectByConfiguredName('raw_package_compressor_class');
-
- // Prepare the decorator compressor (for later flawless and easy updates)
- $compressorInstance = self::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 = self::createObjectByConfiguredName('network_package_class', array($compressorInstance));
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance('network_package', $packageInstance);
- }
-
- // Return the instance
- return $packageInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for fragmenter
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 FragmenterFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton fragmenter instance. If no instance is found, it fill
- * be generated and stored in registry, else the fragmenter from the
- * registry will be returned.
- *
- * @param $fragmenterType The fragmenter's type
- * @return $fragmenterInstance A fragmenter instance
- */
- public static final function createFragmenterInstance ($fragmenterType) {
- // If there is no fragmenter?
- if (Registry::getRegistry()->instanceExists($fragmenterType . '_fragmenter')) {
- // Get fragmenter from registry
- $fragmenterInstance = Registry::getRegistry()->getInstance($fragmenterType . '_fragmenter');
- } else {
- // Get the fragmenter instance
- $fragmenterInstance = self::createObjectByConfiguredName($fragmenterType . '_fragmenter_class');
-
- // Add it to the registry
- Registry::getRegistry()->addInstance($fragmenterType . '_fragmenter', $fragmenterInstance);
- }
-
- // Return the instance
- return $fragmenterInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for producer
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ProducerFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton producer instance. If no instance is found, it fill
- * be generated and stored in registry, else the producer from the
- * registry will be returned.
- *
- * @param $configEntry A configuration entry naming the real class' name
- * @parasm $producerType Type of the producer, can be 'key', 'test_unit', etc.
- * @return $producerInstance A producer instance
- */
- public static final function createProducerInstance ($configEntry, $producerType) {
- // If there is no producer?
- if (Registry::getRegistry()->instanceExists($producerType . '_producer')) {
- // Get producer from registry
- $producerInstance = Registry::getRegistry()->getInstance($producerType . '_producer');
- } else {
- // Get the producer instance
- $producerInstance = self::createObjectByConfiguredName($configEntry);
-
- // Add it to the registry
- Registry::getRegistry()->addInstance($producerType . '_producer', $producerInstance);
- }
-
- // Return the instance
- return $producerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for network packages
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ObjectTypeRegistryFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton object type regsitry.
- *
- * @return $registryInstance A registry for object types
- */
- public static final function createObjectTypeRegistryInstance () {
- // Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists('object_type_registry')) {
- // Then use this instance
- $registryInstance = Registry::getRegistry()->getInstance('object_type_registry');
- } else {
- // Now prepare the tags instance
- $registryInstance = self::createObjectByConfiguredName('node_object_type_registry_class');
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance('object_type_registry', $registryInstance);
- }
-
- // Return the instance
- return $registryInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for ProtocolResolver
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ProtocolResolverFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton (registry-based) ProtocolResolver instance
- *
- * @return $resolverInstance An instance of a ProtocolResolver class
- */
- public static final function createResolverFromConfiguredProtocol () {
- // Get the configured protocol
- $protocolName = FrameworkConfiguration::getSelfInstance()->getConfigEntry('hub_communication_protocol_type');
-
- // If there is no handler?
- if (Registry::getRegistry()->instanceExists($protocolName . '_protocol_resolver')) {
- // Get handler from registry
- $resolverInstance = Registry::getRegistry()->getInstance($protocolName . '_protocol_resolver');
- } else {
- // Get the handler instance
- $resolverInstance = self::createObjectByConfiguredName($protocolName . '_protocol_resolver_class');
-
- // Add it to the registry
- Registry::getRegistry()->addInstance($protocolName . '_protocol_resolver', $resolverInstance);
- }
-
- // Return the instance
- return $resolverInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for scanners
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ScannerObjectFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton (registry-based) Scanner instance
- *
- * @param $taskInstance An instance of a class with an Taskable interface
- * @return $sourceInstance An instance of a Scanner class
- */
- public static final function createScannerInstance (Taskable $taskInstance) {
- // Get new factory instance
- $factoryInstance = new ScannerObjectFactory();
-
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Get scanner type for given task instance by searching it in task handler
- $scannerType = $handlerInstance->searchTask($taskInstance);
-
- // Only let registered tasks pass
- assert(!empty($scannerType));
-
- // If there is no handler?
- if (Registry::getRegistry()->instanceExists('scanner_' . $scannerType)) {
- // Get handler from registry
- $scannerInstance = Registry::getRegistry()->getInstance('scanner_' . $scannerType);
- } else {
- // Get the scanner instance
- $scannerInstance = ObjectFactory::createObjectByConfiguredName($scannerType);
-
- // Add it to the registry
- Registry::getRegistry()->addInstance('scanner_' . $scannerType, $scannerInstance);
- }
-
- // Return the instance
- return $scannerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A socket factory class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 SocketFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates a valid socket resource from given packae data and protocol
- *
- * @param $packageData Raw package data
- * @param $protocolInstance An instance of a HandleableProtocol class
- * @return $socketResource Socket resource
- */
- public static function createSocketFromPackageData (array $packageData, HandleableProtocol $protocolInstance) {
- // Get an instance
- $factoryInstance = new SocketFactory();
-
- // Construct registry key
- $registryKey = 'socket_' . $protocolInstance->getProtocolName() . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT];
-
- // Debug message
- //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to find a socket with registryKey=' . $registryKey);
-
- // Is the key there?
- if (Registry::getRegistry()->instanceExists($registryKey)) {
- // Get container instance
- $containerInstance = Registry::getRegistry()->getInstance($registryKey);
-
- // Get socket back
- $socketResource = $containerInstance->getSocketResource();
-
- // Debug message
- //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Using socket ' . $socketResource . '(' . gettype($socketResource) . ') from registry.');
- } else {
- // Construct configuration entry for object factory and get it
- $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($protocolInstance->getProtocolName() . '_connection_helper_class');
-
- // Debug message
- //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Going to use class ' . $className . ' for creating a socket resource ...');
-
- // And call the static method
- $socketResource = call_user_func($className . '::createConnectionFromPackageData', $packageData);
-
- // Debug message
- //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Created socket ' . $socketResource . '(' . gettype($socketResource) . ') from class ' . $className . '.');
-
- // Construct container class, this won't be reached if an exception is thrown
- $containerInstance = self::CreateObjectByConfiguredName('socket_container_class', array($socketResource, NULL, $packageData));
-
- // Register it with the registry
- Registry::getRegistry()->addInstance($registryKey, $containerInstance);
-
- // Debug message
- //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Socket is now registered in registry.');
- }
-
- // Return the resource
- return $socketResource;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for unit sources
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UnitSourceFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of a configurable and singleton unit source
- *
- * @param $unitType Type of the unit source
- * @return $sourceInstance A UnitSource class instance
- */
- public static final function createUnitSourceInstance ($unitType) {
- // Do we have cache?
- if (!Registry::getRegistry()->instanceExists($unitType . '_unit_source')) {
- // Then construct the class' configuraton entry
- $className = '' . $unitType . '_unit_source_class';
-
- // Get a class from that configuration entry
- $sourceInstance = self::createObjectByConfiguredName($className);
-
- // Add it to the registry
- Registry::getRegistry()->addInstance($unitType . '_unit_source', $sourceInstance);
- } else {
- // Get it from registry
- $sourceInstance = Registry::getRegistry()->getInstance($unitType . '_unit_source');
- }
-
- // For any purposes, return the source instance
- return $sourceInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for URL sources
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 UrlSourceObjectFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Returns a singleton (registry-based) UrlSource instance
- *
- * @param $taskInstance An instance of a class with an Taskable interface
- * @return $sourceInstance An instance of a UrlSource class
- */
- public static final function createUrlSourceInstance (Taskable $taskInstance) {
- // Get new factory instance
- $factoryInstance = new UrlSourceObjectFactory();
-
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Get source type by looking for given task instance in task handler
- $sourceType = $handlerInstance->searchTask($taskInstance);
-
- // Only let registered tasks pass
- assert(!empty($sourceType));
-
- // If there is no handler?
- if (Registry::getRegistry()->instanceExists('source_' . $sourceType)) {
- // Get handler from registry
- $sourceInstance = Registry::getRegistry()->getInstance('source_' . $sourceType);
- } else {
- // Get the source instance
- $sourceInstance = ObjectFactory::createObjectByConfiguredName($sourceType . '_class');
-
- // Add it to the registry
- Registry::getRegistry()->addInstance('source_' . $sourceType, $sourceInstance);
- }
-
- // Return the instance
- return $sourceInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for communicator states
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014, 2015 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 CommunicatorStateFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of a configurable communicator state and sets it in the
- * given communicator instance.
- *
- * @param $stateName Name of the state
- * @param $communicatorInstance A Communicator class instance
- * @return $stateInstance A Stateable class instance
- */
- public static final function createCommunicatorStateInstanceByName ($stateName, Communicator $communicatorInstance) {
- // Then construct the class' configuraton entry
- $className = 'communicator_' . $stateName . '_state_class';
-
- // Get a class from that configuration entry
- $stateInstance = self::createObjectByConfiguredName($className, array($communicatorInstance));
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('COMMUNICATOR-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Communicator state has changed from ' . $communicatorInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Once we have that state, set it in the communicator instance
- $communicatorInstance->setStateInstance($stateInstance);
-
- // Update communicator data
- $communicatorInstance->updateCommunicatorData();
-
- // For any purposes, return the state instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for crawler states
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014, 2015 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 CrawlerStateFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of a configurable crawler state and sets it in the
- * given crawler instance.
- *
- * @param $stateName Name of the state
- * @return $stateInstance A Stateable class instance
- */
- public static final function createCrawlerStateInstanceByName ($stateName) {
- // Then construct the class' configuraton entry
- $className = 'crawler_' . $stateName . '_state_class';
-
- // Get a class from that configuration entry
- $stateInstance = self::createObjectByConfiguredName($className);
-
- // Get crawler instance
- $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Crawler state has changed from ' . $crawlerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Once we have that state, set it in the crawler instance
- $crawlerInstance->setStateInstance($stateInstance);
-
- // Update crawler data
- $crawlerInstance->updateCrawlerData();
-
- // For any purposes, return the state instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for cruncher states
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherStateFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of a configurable cruncher state and sets it in the
- * given cruncher instance.
- *
- * @param $stateName Name of the state
- * @param $cruncherInstance A CruncherHelper class instance
- * @return $stateInstance A Stateable class instance
- */
- public static final function createCruncherStateInstanceByName ($stateName) {
- // Then construct the class' configuraton entry
- $className = 'cruncher_' . $stateName . '_state_class';
-
- // Get cruncher instance from registry
- $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
-
- // Get a class from that configuration entry
- $stateInstance = self::createObjectByConfiguredName($className);
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Cruncher state has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Once we have that state, set it in the cruncher instance
- $cruncherInstance->setStateInstance($stateInstance);
-
- // For any purposes, return the state instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for DHT states
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtStateFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of a configurable DHT state and sets it in the
- * given DHT instance.
- *
- * @param $stateName Name of the state
- * @param $dhtInstance A Distributable class instance
- * @return $stateInstance A Stateable class instance
- */
- public static final function createDhtStateInstanceByName ($stateName, Distributable $dhtInstance) {
- // Then construct the class' configuraton entry
- $className = 'dht_' . $stateName . '_state_class';
-
- // Get a class from that configuration entry
- $stateInstance = self::createObjectByConfiguredName($className, array($dhtInstance));
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: DHT state has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Once we have that state, set it in the DHT instance
- $dhtInstance->setStateInstance($stateInstance);
-
- // Update DHT data
- $dhtInstance->updateDhtData();
-
- // For any purposes, return the state instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for miner states
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerStateFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of a configurable miner state and sets it in the
- * given miner instance.
- *
- * @param $stateName Name of the state
- * @return $stateInstance A Stateable class instance
- */
- public static final function createMinerStateInstanceByName ($stateName) {
- // Then construct the class' configuraton entry
- $className = 'miner_' . $stateName . '_state_class';
-
- // Get miner instance
- $minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Get a class from that configuration entry
- $stateInstance = self::createObjectByConfiguredName($className);
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Miner state has changed from ' . $minerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Once we have that state, set it in the miner instance
- $minerInstance->setStateInstance($stateInstance);
-
- // For any purposes, return the state instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for node states
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeStateFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of a configurable node state and sets it in the
- * given node instance.
- *
- * @param $stateName Name of the state
- * @param $nodeInstance An instance of a NodeHelper class (optional)
- * @return $stateInstance A Stateable class instance
- */
- public static final function createNodeStateInstanceByName ($stateName, NodeHelper $nodeInstance = NULL) {
- // Then construct the class' configuraton entry
- $className = 'node_' . $stateName . '_state_class';
-
- // Is the node instance set?
- if (is_null($nodeInstance)) {
- // Get node instance from registry
- $nodeInstance = NodeObjectFactory::createNodeInstance();
- } // END - if
-
- // Get a class from that configuration entry
- $stateInstance = self::createObjectByConfiguredName($className, array($nodeInstance));
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('NODE-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Node state has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Once we have that state, set it in the node instance
- $nodeInstance->setStateInstance($stateInstance);
-
- // Update node data
- $nodeInstance->updateNodeData();
-
- // For any purposes, return the state instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for peer states
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PeerStateFactory extends ObjectFactory {
- /**
- * Static lookup table instance
- */
- private static $tableInstance = NULL;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Singleton getter for lookup table instances, kept public if we need this
- * table somewhere else.
- *
- * @return $tableInstance An instance of a lookup table
- */
- public static final function getTableInstance () {
- // Is the instance null?
- if (is_null(self::$tableInstance)) {
- // Get a new one
- self::$tableInstance = self::createObjectByConfiguredName('peer_state_lookup_db_wrapper_class');
- } // END - if
-
- // Return it
- return self::$tableInstance;
- }
-
- /**
- * Creates a peer state instance based on errorCode if no entry is found in the lookup table
- * for the peer given in $packageData 'sender' element or it changes the state if it differs
- * from current state.
- *
- * @param $helperInstance An instance of a ConnectionHelper class
- * @param $packageData Raw package data
- * @param $socketResource A valid socket resource
- * @param $errorCode The last error code
- * @return $stateInstance A Stateable class instance
- */
- public static final function createPeerStateInstanceBySocketStatusCode (ConnectionHelper $helperInstance, array $packageData, $socketResource, $errorCode) {
- // Init state instance, this is better coding practice
- $stateInstance = NULL;
-
- // So first we need our lookup table
- $tableInstance = self::getTableInstance();
-
- /*
- * Now try to purge old entries before looking an entry up. This shall
- * make it sure that only accurate entries can be found.
- */
- try {
- // Purge old entries
- $tableInstance->purgeOldEntriesBySocketResource($socketResource);
- } catch (InvalidSocketException $e) {
- // Just log all errors
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Purging of old entries failed. Message from exception: ' . $e->getMessage());
- }
-
- // Do we have an entry?
- if ($tableInstance->isSenderNewPeer($packageData)) {
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] errorCode=' . $errorCode);
-
- // Register the new peer with its session id
- $tableInstance->registerPeerByPackageData($packageData, $socketResource);
-
- /*
- * It is a new peer so create the state instance based on error
- * code and get an instance from it.
- */
- $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class');
-
- // And register it with the lookup table
- $tableInstance->registerPeerState($stateInstance, $packageData);
- } elseif ($tableInstance->isSamePeerState($helperInstance, $packageData)) {
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state unchanged, re-generating old state ...');
-
- /*
- * The peer's state has noot changed, still we have to return a
- * state instance, so generate it here.
- */
- $stateInstance = self::createPeerStateInstanceByName($helperInstance->getPrintableState(), $helperInstance);
- } else {
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Updating peer state ...');
-
- /*
- * It is an already known peer but with a changed state. So first
- * get an instance of the state.
- */
- $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class');
-
- // The peer's state has changed, update database now
- $tableInstance->registerPeerState($stateInstance, $packageData);
- }
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
-
- // Set the state in the helper
- $helperInstance->setStateInstance($stateInstance);
-
- // For any purposes, return the state instance
- return $stateInstance;
- }
-
- /**
- * Creates an instance of a configurable peer state and sets it in the
- * given peer instance.
- *
- * @param $stateName Name of the state
- * @param $helperInstance A ConnectionHelper class instance
- * @return $stateInstance A Stateable class instance
- */
- public static final function createPeerStateInstanceByName ($stateName, ConnectionHelper $helperInstance) {
- // Get a class from a configuration entry
- $stateInstance = self::createObjectByConfiguredName('peer_' . $stateName . '_state_class', array($helperInstance));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
-
- // Once we have that state, set it in the peer instance
- $helperInstance->setStateInstance($stateInstance);
-
- // For any purposes, return the state instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A factory class for network packages
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageTagsFactory extends ObjectFactory {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * 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.
- *
- * @return $packageInstance A network package instance
- */
- public static final function createPackageTagsInstance () {
- // Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists('package_tags')) {
- // Then use this instance
- $packageInstance = Registry::getRegistry()->getInstance('package_tags');
- } else {
- // Now prepare the tags instance
- $packageInstance = self::createObjectByConfiguredName('package_tags_class');
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance('package_tags', $packageInstance);
- }
-
- // Return the instance
- return $packageInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A HubcoinReward Feature class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 HubcoinRewardFeature extends BaseFeature implements Feature {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this Feature class and prepares it for usage
- *
- * @return $featureInstance An instance of this Feature class
- */
- public final static function createHubcoinRewardFeature () {
- // Get a new instance
- $featureInstance = new HubcoinRewardFeature();
-
- // Return the prepared instance
- return $featureInstance;
- }
-
- /**
- * Checks whether this feature can be made available to other classes.
- *
- * @return $isAvailable Whether this feature is available
- */
- public function isFeatureAvailable () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
-
- // Testing this feature is pretty simple:
- $isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === TRUE) && (extension_loaded('scrypt')) && (is_callable('scrypt')));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isAvailable=%d - EXIT!', __METHOD__, __LINE__, intval($isAvailable)));
-
- // Return status
- return $isAvailable;
- }
-
- /**
- * Feature method 'generateHash'
- *
- * @param $data Data to hash
- * @return $hash Finished hash
- */
- public function featureMethodGenerateHash ($data) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d - CALLED!', __METHOD__, __LINE__, strlen($data)));
-
- // Make sure the feature is available
- assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
-
- // Call inner class
- $hash = Scrypt::hashScrypt($data);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: hash=%s - EXIT!', __METHOD__, __LINE__, $hash));
-
- // Return generated hash
- return $hash;
- }
-
- /**
- * Feature method 'checkHash'
- *
- * @param $data Data to check hash for
- * @param $hash Previously generated hash for valdiation
- * @return $isValid Whether the given hash matches a new one from given data
- */
- public function featureMethodCheckHash ($data, $hash) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
-
- // Make sure the feature is available
- assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
-
- // Determine it
- $isValid = Scrypt::checkScrypt($data, $hash);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isValid=%d - EXIT!', __METHOD__, __LINE__, intval($isValid)));
-
- // Return status
- return $isValid;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for hub activation
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 HubActivation???Filter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createHubActivation???Filter () {
- // Get a new instance
- $filterInstance = new HubActivation???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * An Announcement filter for hub activation
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeActivationAnnouncementFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeActivationAnnouncementFilter () {
- // Get a new instance
- $filterInstance = new NodeActivationAnnouncementFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Prepare a self-test task for the listeners
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_task_class');
-
- // Register it
- $handlerInstance->registerTask('announcement', $taskInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Initialization filter for apt-proxy
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyInitializationFilter extends BaseAptProxyFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createAptProxyInitializationFilter () {
- // Get a new instance
- $filterInstance = new AptProxyInitializationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get an instance
- $proxyInstance = ObjectFactory::createObjectByConfiguredName('node_console_apt_proxy_class');
-
- // Get a registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Set the app instance
- $proxyInstance->setApplicationInstance($applicationInstance);
-
- // Add apt-proxy-specific filters
- $proxyInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
-
- // Set the apt_proxy instance in registry
- Registry::getRegistry()->addInstance('apt_proxy', $proxyInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A PhpRequirements filter for apt-proxy
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyPhpRequirementsFilter extends BaseAptProxyFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createAptProxyPhpRequirementsFilter () {
- // Get a new instance
- $filterInstance = new AptProxyPhpRequirementsFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If a required PHP function is not available
- * @todo Add more test and try to add an extra message to the thrown exception
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // By default, the requirement check is passed and zero checks are failed
- $checkPassed = TRUE;
- $checksFailed = 0;
-
- // Socket support is essential...
- if (!function_exists('socket_create')) {
- // Test failed
- $checkPassed = FALSE;
- $checksFailed++;
- } // END -if
-
- // Are all tests passed?
- if ($checkPassed === FALSE) {
- // Throw an exception
- throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A welcome-teaser filter for the apt-proxy
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyWelcomeTeaserFilter extends BaseAptProxyFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createAptProxyWelcomeTeaserFilter () {
- // Get a new instance
- $filterInstance = new AptProxyWelcomeTeaserFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- * @todo Handle over the $responseInstance to outputConsoleTeaser()
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
-
- // Now output the teaser
- $proxyInstance->outputConsoleTeaser();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for bootstrapping apt-proxy
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Apt-Proxy Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 AptProxyBootstrap???Filter extends BaseAptProxyFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createAptProxyBootstrap???Filter () {
- // Get a new instance
- $filterInstance = new AptProxyBootstrap???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get apt-proxy instance
- $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ExtraBootstrapping filter for bootstrapping apt-proxy
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Apt-Proxy 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 AptProxyBootstrapExtraBootstrappingFilter extends BaseAptProxyFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createAptProxyBootstrapExtraBootstrappingFilter () {
- // Get a new instance
- $filterInstance = new AptProxyBootstrapExtraBootstrappingFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $proxyInstance is null (no NullPointerException here)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get apt-proxy instance
- $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
-
- // Do some extra bootstrapping steps
- $proxyInstance->doBootstrapping();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A GenericActivation filter for bootstrapping proxy
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyBootstrapGenericActivationFilter extends BaseAptProxyFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createAptProxyBootstrapGenericActivationFilter () {
- // Get a new instance
- $filterInstance = new AptProxyBootstrapGenericActivationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Maybe we want to do somthing more here?
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a apt-proxy instance
- $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
-
- // Set the flag
- $proxyInstance->enableIsActive();
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: apt-proxy has been activated.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for bootstrapping chats
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ChatBootstrap???Filter extends BaseChatFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createChatBootstrap???Filter () {
- // Get a new instance
- $filterInstance = new ChatBootstrap???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get chat instance
- $chatInstance = Registry::getRegistry()->getInstance('chat');
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ExtraBootstrapping filter for bootstrapping chat
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 ChatBootstrapExtraBootstrappingFilter extends BaseChatFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createChatBootstrapExtraBootstrappingFilter () {
- // Get a new instance
- $filterInstance = new ChatBootstrapExtraBootstrappingFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $chatInstance is null (no NullPointerException here)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get chat instance
- $chatInstance = Registry::getRegistry()->getInstance('chat');
-
- // Do some extra bootstrapping steps
- $chatInstance->doBootstrapping();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A GenericActivation filter for bootstrapping chat
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 ChatBootstrapGenericActivationFilter extends BaseChatFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createChatBootstrapGenericActivationFilter () {
- // Get a new instance
- $filterInstance = new ChatBootstrapGenericActivationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Maybe we want to do somthing more here?
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a chat instance
- $chatInstance = Registry::getRegistry()->getInstance('chat');
-
- // Set the flag
- $chatInstance->enableIsActive();
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: The chat console has been activated.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for bootstrapping crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerBootstrap???Filter extends BaseCrawlerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createCrawlerBootstrap???Filter () {
- // Get a new instance
- $filterInstance = new CrawlerBootstrap???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get crawler instance
- $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ExtraBootstrapping filter for bootstrapping crawler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 CrawlerBootstrapExtraBootstrappingFilter extends BaseCrawlerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCrawlerBootstrapExtraBootstrappingFilter () {
- // Get a new instance
- $filterInstance = new CrawlerBootstrapExtraBootstrappingFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $crawlerInstance is null (no NullPointerException here)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get crawler instance
- $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
-
- // Do some extra bootstrapping steps
- $crawlerInstance->doBootstrapping();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A GenericActivation filter for bootstrapping crawler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 CrawlerBootstrapGenericActivationFilter extends BaseCrawlerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createCrawlerBootstrapGenericActivationFilter () {
- // Get a new instance
- $filterInstance = new CrawlerBootstrapGenericActivationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Maybe we want to do somthing more here?
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a crawler instance
- $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
-
- // Set the flag
- $crawlerInstance->enableIsActive();
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: The crawler has been activated.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for bootstrapping crunchers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CruncherBootstrap???Filter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createCruncherBootstrap???Filter () {
- // Get a new instance
- $filterInstance = new CruncherBootstrap???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get cruncher instance
- $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A BufferQueue filter for bootstrapping crunchers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherBootstrapBufferQueueInitializerFilter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createCruncherBootstrapBufferQueueInitializerFilter () {
- // Get a new instance
- $filterInstance = new CruncherBootstrapBufferQueueInitializerFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get cruncher instance
- $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
-
- // Init all buffer queues
- $cruncherInstance->initBufferQueues();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ExtraBootstrapping filter for bootstrapping crunchers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherBootstrapExtraBootstrappingFilter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCruncherBootstrapExtraBootstrappingFilter () {
- // Get a new instance
- $filterInstance = new CruncherBootstrapExtraBootstrappingFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $cruncherInstance is null (no NullPointerException here)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get cruncher instance
- $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
-
- // Do some extra bootstrapping steps
- $cruncherInstance->doBootstrapping();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A GenericActivation filter for bootstrapping crunchers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherBootstrapGenericActivationFilter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createCruncherBootstrapGenericActivationFilter () {
- // Get a new instance
- $filterInstance = new CruncherBootstrapGenericActivationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Maybe we want to do somthing more here?
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a cruncher instance
- $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
-
- // Set the flag
- $cruncherInstance->enableIsActive();
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: The cruncher has been activated.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for bootstrapping miners
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 MinerBootstrap???Filter extends BaseMinerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createMinerBootstrap???Filter () {
- // Get a new instance
- $filterInstance = new MinerBootstrap???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get miner instance
- $minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A BufferQueue filter for bootstrapping miners
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerBootstrapBufferQueueInitializerFilter extends BaseMinerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createMinerBootstrapBufferQueueInitializerFilter () {
- // Get a new instance
- $filterInstance = new MinerBootstrapBufferQueueInitializerFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get miner instance
- $minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Init all buffer queues
- $minerInstance->initBufferQueues();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ExtraBootstrapping filter for bootstrapping miners
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerBootstrapExtraBootstrappingFilter extends BaseMinerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createMinerBootstrapExtraBootstrappingFilter () {
- // Get a new instance
- $filterInstance = new MinerBootstrapExtraBootstrappingFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $minerInstance is null (no NullPointerException here)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get miner instance
- $minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Do some extra bootstrapping steps
- $minerInstance->doBootstrapping();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A GenericActivation filter for bootstrapping miners
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerBootstrapGenericActivationFilter extends BaseMinerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createMinerBootstrapGenericActivationFilter () {
- // Get a new instance
- $filterInstance = new MinerBootstrapGenericActivationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo Maybe we want to do somthing more here?
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get a miner instance
- $minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Set the flag
- $minerInstance->enableIsActive();
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: The miner has been activated.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for bootstrapping
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 NodeBootstrap???Filter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createNodeBootstrap???Filter () {
- // Get a new instance
- $filterInstance = new NodeBootstrap???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ExtraBootstrapping filter for bootstrapping
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeBootstrapExtraBootstrappingFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeBootstrapExtraBootstrappingFilter () {
- // Get a new instance
- $filterInstance = new NodeBootstrapExtraBootstrappingFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Do some extra bootstrapping steps
- $nodeInstance->doBootstrapping();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A GenerateNodeId filter for bootstrapping
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node 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 NodeBootstrapGenerateNodeIdFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeBootstrapGenerateNodeIdFilter () {
- // Get a new instance
- $filterInstance = new NodeBootstrapGenerateNodeIdFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- /*
- * Acquire a hub-id. This step generates on first launch a new one and
- * on any later launches it will restore the hub-id from the database.
- * A passed 'nickname=xxx' argument will be used to add some
- * 'personality' to the hub.
- */
- $nodeInstance->bootstrapAcquireNodeId($requestInstance, $responseInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A GeneratePrivateKey filter for bootstrapping
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node 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 NodeBootstrapGeneratePrivateKeyFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createNodeBootstrapGeneratePrivateKeyFilter () {
- // Get a new instance
- $filterInstance = new NodeBootstrapGeneratePrivateKeyFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- /*
- * Generate the private key. This will be stored along with the other
- * node data.
- */
- $nodeInstance->bootstrapGeneratePrivateKey();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A GenerateSessionId filter for bootstrapping
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node 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 NodeBootstrapGenerateSessionIdFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeBootstrapGenerateSessionIdFilter () {
- // Get a new instance
- $filterInstance = new NodeBootstrapGenerateSessionIdFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- /*
- * Generate the session id which will only be stored in RAM and kept for
- * the whole "session".
- */
- $nodeInstance->bootstrapGenerateSessionId();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ListenerPool filter for bootstrapping
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Node 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 NodeBootstrapListenerPoolFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeBootstrapListenerPoolFilter () {
- // Get a new instance
- $filterInstance = new NodeBootstrapListenerPoolFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Now do something
- $nodeInstance->initializeListenerPool();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Initialization filter for chat
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 ChatInitializationFilter extends BaseChatFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createChatInitializationFilter () {
- // Get a new instance
- $filterInstance = new ChatInitializationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get an instance
- $chatInstance = ObjectFactory::createObjectByConfiguredName('node_console_chat_class');
-
- // Get a registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Set the app instance
- $chatInstance->setApplicationInstance($applicationInstance);
-
- // Add chat-specific filters
- $chatInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
-
- // Set the chat instance in registry
- Registry::getRegistry()->addInstance('chat', $chatInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A PhpRequirements filter for chat
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat Developer Teama
- * @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 ChatPhpRequirementsFilter extends BaseChatFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createChatPhpRequirementsFilter () {
- // Get a new instance
- $filterInstance = new ChatPhpRequirementsFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If a required PHP function is not available
- * @todo Add more test and try to add an extra message to the thrown exception
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // By default, the requirement check is passed and zero checks are failed
- $checkPassed = TRUE;
- $checksFailed = 0;
-
- // Socket support is essential...
- if (!function_exists('socket_create')) {
- // Test failed
- $checkPassed = FALSE;
- $checksFailed++;
- } // END -if
-
- // Are all tests passed?
- if ($checkPassed === FALSE) {
- // Throw an exception
- throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A welcome-teaser filter for the chat
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 ChatWelcomeTeaserFilter extends BaseChatFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createChatWelcomeTeaserFilter () {
- // Get a new instance
- $filterInstance = new ChatWelcomeTeaserFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- * @todo Handle over the $responseInstance to outputConsoleTeaser()
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $chatInstance = Registry::getRegistry()->getInstance('chat');
-
- // Now output the teaser
- $chatInstance->outputConsoleTeaser();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? filter for !!!
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Hub!!!???Filter extends BaseHubFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createHub!!!???Filter () {
- // Get a new instance
- $filterInstance = new Hub!!!???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A generic filter for apt-proxy sub-project
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 BaseAptProxyFilter extends BaseHubFilter {
- /**
- * Protected constructor
- *
- * @param $className Real name of class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A generic filter for chat sub-project
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 BaseChatFilter extends BaseHubFilter {
- /**
- * Protected constructor
- *
- * @param $className Real name of class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A generic filter for crawler sub-project
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 BaseCrawlerFilter extends BaseHubFilter {
- /**
- * Protected constructor
- *
- * @param $className Real name of class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A generic filter for cruncher sub-project
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 BaseCruncherFilter extends BaseHubFilter {
- /**
- * Protected constructor
- *
- * @param $className Real name of class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A generic filter for hub project
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubFilter extends BaseFilter {
- /**
- * Array with all data XML nodes (which hold the actual data) and their values
- */
- protected $dataXmlNodes = array();
-
- /**
- * Protected constructor
- *
- * @param $className Real name of class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Processes the given raw message content. The method renderXmlContent
- * may throw (not the method itself) several exceptions:
- *
- * InvalidXmlNodeException - If an invalid XML node has been found (e.g.
- * wrong/out-dated template used)
- * XmlNodeMismatchException - Again might be caused by invalid XML node
- * usage
- * XmlParserException - If the XML message is damaged or not
- * well-formed
- *
- * @param $messageType Type of message
- * @param $messageData Raw message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @todo Exceptions from renderXmlContent() are currently unhandled
- */
- protected function genericProcessMessage ($messageType, array $messageData, Receivable $packageInstance) {
- // Make sure the wanted element is there
- assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_MESSAGE]));
- assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_SENDER]));
- assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_HASH]));
- assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_TAGS]));
-
- // Get a template instance from the factory
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_' . $messageType . '_template_class');
-
- // Get message content
- $messageContent = $messageData[NetworkPackage::PACKAGE_CONTENT_MESSAGE];
-
- // And render the XML content (aka message)
- $templateInstance->renderXmlContent($messageContent);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: Handling ' . strlen($messageContent) . ' bytes: ' . $messageContent);
-
- /*
- * The template system now stores all required data as 'general'
- * variables, so simply get them. If there is an invalid XML node
- * inside the message, the above method call will cause exceptions.
- */
- foreach ($this->dataXmlNodes as $key => $dummy) {
- // Call it
- $value = $templateInstance->readXmlData($key);
-
- /*
- * If value is NULL, a variable hasn't been found. This could mean
- * that *this* node is running an out-dated software or the other
- * peer is using an out-dated $messageType.xml template.
- */
- if (is_null($value)) {
- // Output a warning
- self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: Found not fully supported variable ' . $key . ' - skipping.');
-
- // Skip this part, don't write NULLs to the array
- continue;
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: key=' . $key . ',value=' . $value);
-
- // Set it now
- $this->dataXmlNodes[$key] = $value;
- } // END - foreach
-
- // Construct an array for pushing it on next stack
- $messageArray = array(
- // Message data itself
- NetworkPackage::MESSAGE_ARRAY_DATA => $this->dataXmlNodes,
- // Message type (which is $messageType)
- NetworkPackage::MESSAGE_ARRAY_TYPE => $messageType,
- // Message sender
- NetworkPackage::MESSAGE_ARRAY_SENDER => $messageData[NetworkPackage::PACKAGE_CONTENT_SENDER],
- // Package hash
- NetworkPackage::MESSAGE_ARRAY_HASH => $messageData[NetworkPackage::PACKAGE_CONTENT_HASH],
- // Package tags
- NetworkPackage::MESSAGE_ARRAY_TAGS => $messageData[NetworkPackage::PACKAGE_CONTENT_TAGS],
- );
-
- // Push the processed message back on stack
- $packageInstance->getStackInstance()->pushNamed(NetworkPackage::STACKER_NAME_PROCESSED_MESSAGE, $messageArray);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A generic filter for miner sub-project
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 BaseMinerFilter extends BaseHubFilter {
- /**
- * Protected constructor
- *
- * @param $className Real name of class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A generic filter for nodes
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseNodeFilter extends BaseHubFilter {
- /**
- * Protected constructor
- *
- * @param $className Real name of class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Initialization filter for crawler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 CrawlerInitializationFilter extends BaseCrawlerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCrawlerInitializationFilter () {
- // Get a new instance
- $filterInstance = new CrawlerInitializationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get an instance
- $crawlerInstance = ObjectFactory::createObjectByConfiguredName('node_console_crawler_class');
-
- // Get a registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Set the app instance
- $crawlerInstance->setApplicationInstance($applicationInstance);
-
- // Add crawler-specific filters
- $crawlerInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A PhpRequirements filter for crawler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Teama
- * @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 CrawlerPhpRequirementsFilter extends BaseCrawlerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCrawlerPhpRequirementsFilter () {
- // Get a new instance
- $filterInstance = new CrawlerPhpRequirementsFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If a required PHP function is not available
- * @todo Add more test and try to add an extra message to the thrown exception
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // By default, the requirement check is passed and zero checks are failed
- $checkPassed = TRUE;
- $checksFailed = 0;
-
- // Socket support is essential...
- if (!function_exists('socket_create')) {
- // Test failed
- $checkPassed = FALSE;
- $checksFailed++;
- } // END -if
-
- // Are all tests passed?
- if ($checkPassed === FALSE) {
- // Throw an exception
- throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A welcome-teaser filter for the crawler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 CrawlerWelcomeTeaserFilter extends BaseCrawlerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCrawlerWelcomeTeaserFilter () {
- // Get a new instance
- $filterInstance = new CrawlerWelcomeTeaserFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- * @todo Handle over the $responseInstance to outputConsoleTeaser()
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
-
- // Now output the teaser
- $crawlerInstance->outputConsoleTeaser();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for crunchers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Cruncher???Filter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createCruncher???Filter () {
- // Get a new instance
- $filterInstance = new Cruncher???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Implement this!
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A Initialization filter for crunchers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherInitializationFilter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCruncherInitializationFilter () {
- // Get a new instance
- $filterInstance = new CruncherInitializationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // The default cruncher-mode is from our configuration
- $cruncherMode = $this->getConfigInstance()->getConfigEntry('cruncher_default_mode');
-
- // Is the cruncher 'mode' parameter set?
- if ($requestInstance->isRequestElementSet('mode')) {
- // Then use this which overrides the config entry temporarily
- $cruncherMode = $requestInstance->getRequestElement('mode');
- } else {
- // Set it for easier re-usage
- $requestInstance->setRequestElement('mode', $cruncherMode);
- }
-
- // Now convert the cruncher-mode in a class name
- $className = 'Hub' . self::convertToClassName($cruncherMode) . 'Cruncher';
-
- // And try to instance it
- try {
- // Get an instance
- $cruncherInstance = ObjectFactory::createObjectByName($className);
-
- // Get a registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Set the app instance
- $cruncherInstance->setApplicationInstance($applicationInstance);
-
- // Add cruncher-specific filters
- $cruncherInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
- } catch (ClassNotFoundException $e) {
- // This exception means, the cruncher mode is invalid.
- // @TODO Can we rewrite this to app_exit() ?
- $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: cruncher mode ' . $cruncherMode . ' is invalid.');
- }
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A PhpRequirements filter for crunchers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherPhpRequirementsFilter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCruncherPhpRequirementsFilter () {
- // Get a new instance
- $filterInstance = new CruncherPhpRequirementsFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If a required PHP function is not available
- * @todo Add more test and try to add an extra message to the thrown exception
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // By default, the requirement check is passed and zero checks are failed
- $checkPassed = TRUE;
- $checksFailed = 0;
-
- // Socket support is essential...
- if (!function_exists('socket_create')) {
- // Test failed
- $checkPassed = FALSE;
- $checksFailed++;
- } // END -if
-
- // Are all tests passed?
- if ($checkPassed === FALSE) {
- // Throw an exception
- throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A welcome-teaser filter for the cruncher
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherWelcomeTeaserFilter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCruncherWelcomeTeaserFilter () {
- // Get a new instance
- $filterInstance = new CruncherWelcomeTeaserFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- * @todo Handle over the $responseInstance to outputConsoleTeaser()
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
-
- // Now output the teaser
- $cruncherInstance->outputConsoleTeaser();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for miners
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Miner???Filter extends BaseminerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createMiner???Filter () {
- // Get a new instance
- $filterInstance = new Miner???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Implement this!
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A Initialization filter for miners
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerInitializationFilter extends BaseMinerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createMinerInitializationFilter () {
- // Get a new instance
- $filterInstance = new MinerInitializationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // The default miner-mode is from our configuration
- $minerMode = $this->getConfigInstance()->getConfigEntry('miner_default_mode');
-
- // Is the miner 'mode' parameter set?
- if ($requestInstance->isRequestElementSet('mode')) {
- // Then use this which overrides the config entry temporarily
- $minerMode = $requestInstance->getRequestElement('mode');
- } else {
- // Set it for easier re-usage
- $requestInstance->setRequestElement('mode', $minerMode);
- }
-
- // Now convert the miner-mode in a class name
- $className = 'Hub' . self::convertToClassName($minerMode) . 'Miner';
-
- // And try to instance it
- try {
- // Get an instance
- $minerInstance = ObjectFactory::createObjectByName($className);
-
- // Get a registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Set the app instance
- $minerInstance->setApplicationInstance($applicationInstance);
-
- // Add miner-specific filters
- $minerInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance);
- } catch (ClassNotFoundException $e) {
- // This exception means, the miner mode is invalid.
- // @TODO Can we rewrite this to app_exit() ?
- $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: miner mode ' . $minerMode . ' is invalid.');
- }
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A PhpRequirements filter for miners
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerPhpRequirementsFilter extends BaseMinerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createMinerPhpRequirementsFilter () {
- // Get a new instance
- $filterInstance = new MinerPhpRequirementsFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If a required PHP function is not available
- * @todo Add more test and try to add an extra message to the thrown exception
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // By default, the requirement check is passed and zero checks are failed
- $checkPassed = TRUE;
- $checksFailed = 0;
-
- // Socket support is essential...
- if (!function_exists('socket_create')) {
- // Test failed
- $checkPassed = FALSE;
- $checksFailed++;
- } // END -if
-
- // If scrypt() is not found (ext-scrypt) then the "Hubcoins reward" is not working
- if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) {
- // Mark it as working
- self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature possible.');
- $this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE);
- } else {
- // Not working (not all have ext-scrypt installed
- self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
- }
-
- // Are all tests passed?
- if ($checkPassed === FALSE) {
- // Throw an exception
- throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A welcome-teaser filter for the miner
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerWelcomeTeaserFilter extends BaseMinerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createMinerWelcomeTeaserFilter () {
- // Get a new instance
- $filterInstance = new MinerWelcomeTeaserFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- * @todo Handle over the $responseInstance to outputConsoleTeaser()
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Now output the teaser
- $minerInstance->outputConsoleTeaser();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for nodes
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Node???Filter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createNode???Filter () {
- // Get a new instance
- $filterInstance = new Node???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Implement this!
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A Initialization filter for nodes
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeInitializationFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeInitializationFilter () {
- // Get a new instance
- $filterInstance = new NodeInitializationFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Try to instance it by using a factory
- try {
- // Get an instance
- $nodeInstance = NodeObjectFactory::createNodeInstance($requestInstance, $responseInstance);
- } catch (ClassNotFoundException $e) {
- // This exception means, the node mode is invalid.
- // @TODO Can we rewrite this to app_exit() ?
- $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: node mode ' . $nodeMode . ' is invalid.');
- }
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE-INIT-FILTER[' . __METHOD__ . ':' . __LINE__ . ']: Node ' . $nodeMode . ' has been added to registry.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A PhpRequirements filter for nodes
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodePhpRequirementsFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodePhpRequirementsFilter () {
- // Get a new instance
- $filterInstance = new NodePhpRequirementsFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If a required PHP function is not available
- * @todo Add more test and try to add an extra message to the thrown exception
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // By default, the requirement check is passed and zero checks are failed
- $checkPassed = TRUE;
- $checksFailed = 0;
-
- // Socket support is essential...
- if (!function_exists('socket_create')) {
- // Test failed
- $checkPassed = FALSE;
- $checksFailed++;
- } // END - if
-
- // If scrypt() is not found (ext-scrypt) then the "Hubcoins reward" is not working
- if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) {
- // Mark it as working
- self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature possible.');
- $this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE);
- } else {
- // Not working (not all have ext-scrypt installed
- self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
- }
-
- // Are all tests passed?
- if ($checkPassed === FALSE) {
- // Throw an exception
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A welcome-teaser filter for the console
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeWelcomeTeaserFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeWelcomeTeaserFilter () {
- // Get a new instance
- $filterInstance = new NodeWelcomeTeaserFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- * @todo Handle over the $responseInstance to outputConsoleTeaser()
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Now output the teaser
- $nodeInstance->outputConsoleTeaser();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A shutdown filter for shutting down the apt-proxy. This filter should be the
- * last one in 'shutdown' chain so the apt-proxy is shutted down at the very
- * end of its life...
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy 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 AptProxyShutdownFilter extends BaseAptProxyFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createAptProxyShutdownFilter () {
- // Get a new instance
- $filterInstance = new AptProxyShutdownFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $proxyInstance = Registry::getRegistry()->getInstance('apt_proxy');
-
- // Shutdown the apt-proxy. This should be the last line
- $proxyInstance->doShutdown();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A shutdown filter for shutting down the chat console. This filter should be
- * the last one in 'shutdown' chain so the chat is shutted down at the very end
- * of its life...
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 ChatShutdownFilter extends BaseChatFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createChatShutdownFilter () {
- // Get a new instance
- $filterInstance = new ChatShutdownFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $chatInstance = Registry::getRegistry()->getInstance('chat');
-
- // Shutdown the chat. This should be the last line
- $chatInstance->doShutdown();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A shutdown filter for shutting down the crawler. This filter should be the
- * last one in 'shutdown' chain so the crawler is shutted down at the very end
- * of its life...
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 CrawlerShutdownFilter extends BaseCrawlerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCrawlerShutdownFilter () {
- // Get a new instance
- $filterInstance = new CrawlerShutdownFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $crawlerInstance = Registry::getRegistry()->getInstance('crawler');
-
- // Shutdown the crawler. This should be the last line
- $crawlerInstance->doShutdown();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A shutdown filter for shutting down the cruncher. This filter should be the
- * last one in 'shutdown' chain so the hub is shutted down at the very end of
- * its life... R.I.P. little cruncher...
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherShutdownFilter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCruncherShutdownFilter () {
- // Get a new instance
- $filterInstance = new CruncherShutdownFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
-
- // Shutdown the cruncher. This should be the last line
- $cruncherInstance->doShutdown();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A shutdown filter for shutting down the miner. This filter should be the
- * last one in 'shutdown' chain so the hub is shutted down at the very end of
- * its life... R.I.P. little miner...
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerShutdownFilter extends BaseMinerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createMinerShutdownFilter () {
- // Get a new instance
- $filterInstance = new MinerShutdownFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Shutdown the miner. This should be the last line
- $minerInstance->doShutdown();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? filter for shutting down the node.
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 HubShutdown???Filter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createHubShutdown???Filter () {
- // Get a new instance
- $filterInstance = new HubShutdown???Filter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A FlushNodeList filter for shutting down the node.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeShutdownFlushNodeListFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeShutdownFlushNodeListFilter () {
- // Get a new instance
- $filterInstance = new NodeShutdownFlushNodeListFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Now do something
- $this->partialStub('Please implement this step.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ShutdownNode filter for shutting down the node. This filter should be the
- * last one in 'shutdown' chain so the hub is shutted down at the very end of
- * its life... R.I.P. little hub...
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeShutdownNodeFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeShutdownNodeFilter () {
- // Get a new instance
- $filterInstance = new NodeShutdownNodeFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException please)
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Shutdown the node. This should be the last line
- $nodeInstance->doShutdown();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A TaskHandler filter for shutting down the node.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeShutdownTaskHandlerFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeShutdownTaskHandlerFilter () {
- // Get a new instance
- $filterInstance = new NodeShutdownTaskHandlerFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If $nodeInstance is null (no NullPointerException here)
- * @todo 0% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Shutdown the task manager and all its registered tasks
- $handlerInstance->doShutdown();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A AnnouncementAnswerTag filter for Package
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageAnnouncementAnswerTagFilter extends BaseNodeFilter implements FilterablePackage {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->dataXmlNodes = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => '',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => '',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID => '',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '',
- BaseXmlAnswerTemplateEngine::ANSWER_STATUS => '',
- );
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createPackageAnnouncementAnswerTagFilter () {
- // Get a new instance
- $filterInstance = new PackageAnnouncementAnswerTagFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Processes the given raw message content. The method renderXmlContent
- * may throw (not the method itself) several exceptions:
- *
- * @param $messageData Raw message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function processMessage (array $messageData, Receivable $packageInstance) {
- // Process message in generic way
- $this->genericProcessMessage('announcement_answer', $messageData, $packageInstance);
- }
-
- /**
- * Post-processes the stacked message. Do not call popNamed() as then no
- * other class can process the message.
- *
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function postProcessMessage (Receivable $packageInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A DhtBootstrapAnswerTag filter for Package
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageDhtBootstrapAnswerTagFilter extends BaseNodeFilter implements FilterablePackage {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->dataXmlNodes = array(
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => '',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_LIST => '',
- BaseXmlAnswerTemplateEngine::ANSWER_STATUS => '',
- );
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createPackageDhtBootstrapAnswerTagFilter () {
- // Get a new instance
- $filterInstance = new PackageDhtBootstrapAnswerTagFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Processes the given raw message content. The method renderXmlContent
- * may throw (not the method itself) several exceptions:
- *
- * @param $messageData Raw message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function processMessage (array $messageData, Receivable $packageInstance) {
- // Process message in generic way
- $this->genericProcessMessage('dht_bootstrap_answer', $messageData, $packageInstance);
- }
-
- /**
- * Post-processes the stacked message. Do not call popNamed() as then no
- * other class can process the message.
- *
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function postProcessMessage (Receivable $packageInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A RequestNodeListAnswerTag filter for Package
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageRequestNodeListAnswerTagFilter extends BaseNodeFilter implements FilterablePackage {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->dataXmlNodes = array(
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID => '',
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST => '',
- BaseXmlAnswerTemplateEngine::ANSWER_STATUS => '',
- );
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createPackageRequestNodeListAnswerTagFilter () {
- // Get a new instance
- $filterInstance = new PackageRequestNodeListAnswerTagFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Processes the given raw message content. The method renderXmlContent
- * may throw (not the method itself) several exceptions:
- *
- * @param $messageData Raw message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function processMessage (array $messageData, Receivable $packageInstance) {
- // Process message in generic way
- $this->genericProcessMessage('request_node_list_answer', $messageData, $packageInstance);
- }
-
- /**
- * Post-processes the stacked message. Do not call popNamed() as then no
- * other class can process the message.
- *
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function postProcessMessage (Receivable $packageInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A AnnouncementTag filter for packages
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageAnnouncementTagFilter extends BaseNodeFilter implements FilterablePackage {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->dataXmlNodes = array(
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => '',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => '',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE => '',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID => '',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => '',
- );
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createPackageAnnouncementTagFilter () {
- // Get a new instance
- $filterInstance = new PackageAnnouncementTagFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Processes the given raw message content. The method renderXmlContent
- * may throw (not the method itself) several exceptions:
- *
- * InvalidXmlNodeException - If an invalid XML node has been found (e.g.
- * wrong/out-dated template used)
- * XmlNodeMismatchException - Again might be caused by invalid XML node
- * usage
- * XmlParserException - If the XML message is damaged or not
- * well-formed
- *
- * @param $messageData Raw message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function processMessage (array $messageData, Receivable $packageInstance) {
- // Process message generic
- $this->genericProcessMessage('announcement', $messageData, $packageInstance);
- }
-
- /**
- * Post-processes the stacked message. Do not call popNamed() as then no
- * other class can process the message.
- *
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function postProcessMessage (Receivable $packageInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A DhtBootstrapTag filter for packages
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageDhtBootstrapTagFilter extends BaseNodeFilter implements FilterablePackage {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->dataXmlNodes = array(
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => '',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => '',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => '',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE => '',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => '',
- );
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createPackageDhtBootstrapTagFilter () {
- // Get a new instance
- $filterInstance = new PackageDhtBootstrapTagFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Processes the given raw message content. The method renderXmlContent
- * may throw (not the method itself) several exceptions:
- *
- * InvalidXmlNodeException - If an invalid XML node has been found (e.g.
- * wrong/out-dated template used)
- * XmlNodeMismatchException - Again might be caused by invalid XML node
- * usage
- * XmlParserException - If the XML message is damaged or not
- * well-formed
- *
- * @param $messageData Raw message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function processMessage (array $messageData, Receivable $packageInstance) {
- // Process message generic
- $this->genericProcessMessage('dht_bootstrap', $messageData, $packageInstance);
- }
-
- /**
- * Post-processes the stacked message. Do not call popNamed() as then no
- * other class can process the message.
- *
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function postProcessMessage (Receivable $packageInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A RequestNodeListTag filter for packages
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageRequestNodeListTagFilter extends BaseNodeFilter implements FilterablePackage {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init XML nodes array which contains the required data
- $this->dataXmlNodes = array(
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES => '',
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => '',
- );
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createPackageRequestNodeListTagFilter () {
- // Get a new instance
- $filterInstance = new PackageRequestNodeListTagFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Processes the given raw message content.
- *
- * @param $messageData Raw message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function processMessage (array $messageData, Receivable $packageInstance) {
- // Process messasge generic
- $this->genericProcessMessage('request_node_list', $messageData, $packageInstance);
- }
-
- /**
- * Post-processes the stacked message. Do not call popNamed() as then no
- * other class can process the message.
- *
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- public function postProcessMessage (Receivable $packageInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A SelfConnectTag filter for packages
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageSelfConnectTagFilter extends BaseNodeFilter implements FilterablePackage {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->dataXmlNodes = array(
- XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID => '',
- XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID => '',
- );
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public final static function createPackageSelfConnectTagFilter () {
- // Get a new instance
- $filterInstance = new PackageSelfConnectTagFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Processes the given raw message content. The method renderXmlContent
- * may throw (not the method itself) several exceptions:
- *
- * InvalidXmlNodeException - If an invalid XML node has been found (e.g.
- * wrong/out-dated template used)
- * XmlNodeMismatchException - Again might be caused by invalid XML node
- * usage
- * XmlParserException - If the XML message is damaged or not
- * well-formed
- *
- * @param $messageData Raw message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function processMessage (array $messageData, Receivable $packageInstance) {
- // Process generic
- $this->genericProcessMessage('self_connect', $messageData, $packageInstance);
- }
-
- /**
- * Post-processes the stacked message. Do not call popNamed() as then no
- * other class can process the message.
- *
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
- */
- public function postProcessMessage (Receivable $packageInstance) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TaskHandlerInitializer filter for apt-proxy
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 apt-proxy 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 AptProxyTaskHandlerInitializerFilter extends BaseAptProxyFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createAptProxyTaskHandlerInitializerFilter () {
- // Get a new instance
- $filterInstance = new AptProxyTaskHandlerInitializerFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If the filter chain needs to be interrupted
- * @todo 5% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get apt-proxy instance
- //$chatInstance = Registry::getRegistry()->getInstance('chat');
-
- // Get a new task handler instance
- $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
-
- // Put the task handler in registry
- Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
-
- /*
- * Register all tasks:
- *
- * 1) apt-proxy listener
- */
- $taskInstance = ObjectFactory::createObjectByConfiguredName('apt_proxy_listener_task_class');
- $handlerInstance->registerTask('apt_proxy_listener', $taskInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TaskHandlerInitializer filter for chat
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 ChatTaskHandlerInitializerFilter extends BaseChatFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createChatTaskHandlerInitializerFilter () {
- // Get a new instance
- $filterInstance = new ChatTaskHandlerInitializerFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If the filter chain needs to be interrupted
- * @todo 5% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get chat instance
- //$chatInstance = Registry::getRegistry()->getInstance('chat');
-
- // Get a new task handler instance
- $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
-
- // Put the task handler in registry
- Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
-
- /*
- * Register all tasks:
- *
- * 1) Telnet session listener
- */
- $taskInstance = ObjectFactory::createObjectByConfiguredName('chat_telnet_listener_task_class');
- $handlerInstance->registerTask('chat_telnet_listener', $taskInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TaskHandlerInitializer filter for crawler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 CrawlerTaskHandlerInitializerFilter extends BaseCrawlerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCrawlerTaskHandlerInitializerFilter () {
- // Get a new instance
- $filterInstance = new CrawlerTaskHandlerInitializerFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If the filter chain needs to be interrupted
- * @todo 10% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get crawler instance
- //$crawlerInstance = Registry::getRegistry()->getInstance('crawler');
-
- // Get a new task handler instance
- $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
-
- // Put the task handler in registry
- Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
-
- /*
- * Register all tasks:
- *
- * 1) "Communicator" for crawler->node communication
- */
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_node_communicator_task_class');
- $handlerInstance->registerTask('crawler_node_communicator', $taskInstance);
-
- // 2) Local URL crawler (gets URLs locally and adds them to the analyzer's input stack)
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_local_url_crawler_task_class');
- $handlerInstance->registerTask('crawler_local_url_crawler', $taskInstance);
-
- // 3) Remote URL crawler (gets URLs locally for other nodes, also includes the crawled URL in local index)
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_remote_url_crawler_task_class');
- $handlerInstance->registerTask('crawler_remote_url_crawler', $taskInstance);
-
- // 4) Remote-crawl publisher (publishes crawl jobs for remote retrieval)
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_remote_job_publisher_task_class');
- $handlerInstance->registerTask('crawler_remote_job_publisher', $taskInstance);
-
- // 5) MIME sniffer
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_mime_sniffer_task_class');
- $handlerInstance->registerTask('crawler_mime_sniffer', $taskInstance);
-
- // 6) Document parser (converts document to meta format)
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_document_parser_task_class');
- $handlerInstance->registerTask('crawler_document_parser', $taskInstance);
-
- // 7) Document structure analyzer
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_structure_analyzer_task_class');
- $handlerInstance->registerTask('crawler_structure_analyzer', $taskInstance);
-
- // 8) Snippet extractor
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_snippet_extractor_task_class');
- $handlerInstance->registerTask('crawler_snippet_extractor', $taskInstance);
-
- // 9) Node ping
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_ping_task_class');
- $handlerInstance->registerTask('crawler_ping', $taskInstance);
-
- // 10) URL sources
- foreach (explode(':', $this->getConfigInstance()->getConfigEntry('crawler_url_stacks')) as $stack) {
- // Init task instance
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_url_source_' . $stack . '_task_class');
-
- // And register it
- $handlerInstance->registerTask('crawler_url_source_' . $stack, $taskInstance);
- } // END - foreach
-
- // 11) Uploaded list scanner (checks for wanted files)
- $taskInstance = ObjectFactory::createObjectByConfiguredName('crawler_uploaded_list_scanner_task_class');
- $handlerInstance->registerTask('crawler_uploaded_list_scanner', $taskInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TaskHandlerInitializer filter for crunchers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherTaskHandlerInitializerFilter extends BaseCruncherFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createCruncherTaskHandlerInitializerFilter () {
- // Get a new instance
- $filterInstance = new CruncherTaskHandlerInitializerFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If the filter chain needs to be interrupted
- * @todo 5% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get cruncher instance
- //$cruncherInstance = Registry::getRegistry()->getInstance('cruncher');
-
- // Get a new task handler instance
- $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
-
- // Put the task handler in registry
- Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
-
- // Register all tasks:
- //
- // 1) A task for fetching WUs (work units) or test units
- $taskInstance = ObjectFactory::createObjectByConfiguredName('cruncher_work_unit_fetcher_task_class');
- $handlerInstance->registerTask('cruncher_work_unit_fetcher', $taskInstance);
-
- /*
- * 2) A task for generating test units, a if() block could be placed
- * around this but that would make this method look a little ugly and
- * even more when more "temporary" tasks should be registered.
- */
- $taskInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_producer_task_class');
- $handlerInstance->registerTask('cruncher_test_unit_producer', $taskInstance);
-
- /*
- * 3) A task for generating keys based on the generated test unit. This
- * task will only be executed if the state of the cruncher is one of
- * these: 'virgin'.
- */
- $taskInstance = ObjectFactory::createObjectByConfiguredName('cruncher_key_producer_task_class');
- $handlerInstance->registerTask('cruncher_key_producer', $taskInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TaskHandlerInitializer filter for miners
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerTaskHandlerInitializerFilter extends BaseMinerFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createMinerTaskHandlerInitializerFilter () {
- // Get a new instance
- $filterInstance = new MinerTaskHandlerInitializerFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If the filter chain needs to be interrupted
- * @todo 5% done
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get miner instance
- //$minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Get a new task handler instance
- $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
-
- // Put the task handler in registry
- Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
-
- // Register all tasks:
- //
- // 1) A task for fetching blocks from the network
- $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_block_fetcher_task_class');
- $handlerInstance->registerTask('miner_block_fetcher', $taskInstance);
-
- /*
- * 2) A task for generating a test "genesis" block. This "block"
- * consists of several hashes of famous phrases or "catch lines" from
- * free-software authors.
- */
- $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_test_genesis_block_producer_task_class');
- $handlerInstance->registerTask('miner_test_genesis_block_producer', $taskInstance);
-
- /*
- * 3) A task for generating a real "genesis" block. @TODO Define how a
- * real "genesis" block is generated
- */
- $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_real_genesis_block_producer_task_class');
- $handlerInstance->registerTask('miner_real_genesis_block_producer', $taskInstance);
-
- /*
- * 4) A task for communicating into the locally running 'hub' node.
- * This rask will check for new blocks on the mining network and
- * tries to claim found blocks.
- */
- $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_node_communicator_task_class');
- $handlerInstance->registerTask('miner_node_communicator', $taskInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TaskHandlerInitializer filter for hubs
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeTaskHandlerInitializerFilter extends BaseNodeFilter implements Filterable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this filter class
- *
- * @return $filterInstance An instance of this filter class
- */
- public static final function createNodeTaskHandlerInitializerFilter () {
- // Get a new instance
- $filterInstance = new NodeTaskHandlerInitializerFilter();
-
- // Return the instance
- return $filterInstance;
- }
-
- /**
- * Executes the filter with given request and response objects
- *
- * @param $requestInstance An instance of a class with an Requestable interface
- * @param $responseInstance An instance of a class with an Responseable interface
- * @return void
- * @throws FilterChainException If the filter chain needs to be interrupted
- * @todo Maybe some more tasks needs to be added?
- */
- public function execute (Requestable $requestInstance, Responseable $responseInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Get a new task handler instance
- $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
-
- // Put the task handler in registry
- Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
-
- // Prepare a package-tags initialization task for the listeners
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_package_tags_init_task_class');
-
- // Register it
- $handlerInstance->registerTask('package_tags_init', $taskInstance);
-
- // Generate package writer task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_package_writer_task_class');
-
- // Register it as well
- $handlerInstance->registerTask('network_package_writer', $taskInstance);
-
- // Generate package reader task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_package_reader_task_class');
-
- // Network package reader, needs to be delayed a little
- $handlerInstance->registerTask('network_package_reader', $taskInstance);
-
- // Generate socket listener task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_socket_listener_task_class');
-
- // Network package reader, needs to be delayed a little
- $handlerInstance->registerTask('socket_listener', $taskInstance);
-
- // Generate package decoder task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_package_decoder_task_class');
-
- // Register it as well
- $handlerInstance->registerTask('package_decoder', $taskInstance);
-
- // Generate chunk assembler task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_chunk_assembler_task_class');
-
- // Register it as well
- $handlerInstance->registerTask('chunk_assembler', $taskInstance);
-
- // Generate DHT initialization task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_init_task_class');
-
- // Register it as well
- $handlerInstance->registerTask('dht_init', $taskInstance);
-
- // Generate DHT query task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_query_task_class');
-
- // Register it as well
- $handlerInstance->registerTask('dht_query', $taskInstance);
-
- // Generate DHT publication-check task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_publication_check_task_class');
-
- // Register it as well
- $handlerInstance->registerTask('dht_check_publication', $taskInstance);
-
- // Generate DHT publication task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_publication_task_class');
-
- // Register it as well
- $handlerInstance->registerTask('dht_publication', $taskInstance);
-
- // Prepare a self-test task for the listeners
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_selfconnect_task_class');
-
- // Register it
- $handlerInstance->registerTask('self_connect', $taskInstance);
-
- // Prepare a update-check task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_update_check_task_class');
-
- // Register it
- $handlerInstance->registerTask('update_check', $taskInstance);
-
- // Get the list instance here
- $listInstance = $nodeInstance->getListenerPoolInstance()->getPoolEntriesInstance();
-
- // Prepare a ping task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_ping_task_class', array($listInstance));
-
- // Register it
- $handlerInstance->registerTask('ping', $taskInstance);
-
- /*
- * Allow extra node-depending tasks, e.g. the bootstrapper node needs
- * booting its DHT. DHTs are decentralized and are working on
- * peer-to-peer basis.
- */
- $nodeInstance->addExtraTasks($handlerInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A AnnouncementAnswerOkay handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->searchData = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- );
-
- // Set handler name
- $this->setHandlerName('announcement_answer_okay');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createAnnouncementAnswerOkayHandler () {
- // Get new instance
- $handlerInstance = new AnnouncementAnswerOkayHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles given message data array
- *
- * @param $messageData An array of message data
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @todo Do some more here: Handle karma, et cetera?
- */
- public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
- /*
- * Query DHT and force update (which will throw an exception if the
- * node is not found).
- */
- $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
-
- // Get handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Generate DHT bootstrap task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
-
- // Register it as well
- $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
-
- // Get the node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Change state
- $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
-
- // Prepare next message
- $this->prepareNextMessage($messageData, $packageInstance);
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * The following array is being handled over:
- *
- * my-external-address => 1.2.3.4
- * my-internal-address => 5.6.7.8
- * my-status => reachable
- * my-node-id => aaabbbcccdddeeefff123456789
- * my-session-id => aaabbbcccdddeeefff123456789
- * my-tcp-port => 9060
- * my-udp-port => 9060
- * answer-status => OKAY
- * message_type => announcement_answer
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Get an array of all accepted object types
- $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
-
- // Add missing (temporary) configuration 'accepted_object_types'
- $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration. For content of $messageData see method comment above.
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Remove temporay configuration
- $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? handler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Handler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('|||_answer_===');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function create???Handler () {
- // Get new instance
- $handlerInstance = new ???Handler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles given message data array
- *
- * @param $messageData An array of message data
- * @return void
- */
- public function handleAnswerMessageData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general answer-status handler. So called "answer-status handler" are
- * classes which handles a message field 'answer-status' which is, alongside
- * many other node-relevant data, the main part of the answer message. These
- * answer messages, by the way, are never sent unrequested. This, however,
- * sounds logical because the answer is a reply from a node that has responded
- * on a message.
- *
- * The answer-status field gives information back to the requesting node if the
- * receiving node could handle the message properly (all verfication steps are
- * passed, message type was understood, correct receiver, et cetera) and how
- * it handles it. Some messages may be rejected, e.g. when the requesting node
- * is blacklisted or its behavour has changed.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
- */
-abstract class BaseAnserStatusHandler extends BaseDataHandler {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A RequestNodeListAnswerOkay handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->searchData = array(
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
- );
-
- // Set handler name
- $this->setHandlerName('request_node_list_answer_okay');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createRequestNodeListAnswerOkayHandler () {
- // Get new instance
- $handlerInstance = new RequestNodeListAnswerOkayHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles given message data array
- *
- * @param $messageData An array of message data
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws NodeSessionIdVerficationException If the provided session id is not matching
- * @todo Do some more here: Handle karma, et cetera?
- */
- public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
- // Make sure node-list is found in array
- assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
-
- // Save node list
- $nodeList = json_decode(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
-
- // Make sure it is completely decoded
- assert(is_array($nodeList));
-
- // ... and remove it as it should not be included now
- unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
-
- // Write node list to DHT
- $this->getDhtInstance()->insertNodeList($nodeList);
-
- /*
- * Query DHT and force update (which will throw an exception if the
- * node is not found).
- */
- $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
-
- // Prepare next message ("hello" message to all returned nodes)
- //$this->prepareNextMessage($messageData, $packageInstance);
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * The following array is being handled over:
- *
- * session-id => aaabbbcccdddeeefff123456789
- * node-list => aabb:ccdd:eeff
- * answer-status => OKAY
- * message_type => request_node_list_answer
- *
- * @param $messageData An array with all message data
- * @return void
- * @todo 0% done
- */
- protected function initMessageConfigurationData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration. For content of $messageData see method comment above.
- *
- * @param $messageData An array with all message data
- * @return void
- * @todo 0% done
- */
- protected function removeMessageConfigurationData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Chunk handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ChunkHandler extends BaseHandler implements HandleableChunks, Registerable {
- /**
- * Stacker for chunks with final EOP
- */
- const STACKER_NAME_CHUNKS_WITH_FINAL_EOP = 'final_chunks';
- const STACKER_NAME_CHUNKS_WITHOUT_FINAL = 'pending_chunks';
- const STACKER_NAME_ASSEMBLED_RAW_DATA = 'chunk_raw_data';
-
- /**
- * Chunk splits:
- * 0 = Hash
- * 1 = Serial number
- * 2 = Raw data
- */
- const CHUNK_SPLITS_INDEX_HASH = 0;
- const CHUNK_SPLITS_INDEX_SERIAL = 1;
- const CHUNK_SPLITS_INDEX_RAW_DATA = 2;
-
- /**
- * The final array for assembling the original package back together
- */
- private $finalPackageChunks = array();
-
- /**
- * Array of chunk hashes
- */
- private $chunkHashes = array();
-
- /**
- * Raw EOP chunk data in an array:
- *
- * 0 = Final hash,
- * 1 = Hash of last chunk
- */
- private $eopChunk = array();
-
- /**
- * Raw package data
- */
- private $rawPackageData = '';
-
- /**
- * Fragmenter instance, needs to be set here again
- */
- private $fragmenterInstance = NULL;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('chunk');
-
- // Initialize handler
- $this->initHandler();
-
- // Get a fragmenter instance for later verification of serial numbers (e.g. if all are received)
- $fragmenterInstance = FragmenterFactory::createFragmenterInstance('package');
-
- // Set it in this handler
- $this->fragmenterInstance = $fragmenterInstance;
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a chunk Handler class
- */
- public final static function createChunkHandler () {
- // Get new instance
- $handlerInstance = new ChunkHandler();
-
- // Get a FIFO stacker
- $stackInstance = ObjectFactory::createObjectByConfiguredName('chunk_handler_stacker_class');
-
- // Init all stacker
- $stackInstance->initStacks(array(
- self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP,
- self::STACKER_NAME_CHUNKS_WITHOUT_FINAL,
- self::STACKER_NAME_ASSEMBLED_RAW_DATA
- ));
-
- // Set the stacker in this handler
- $handlerInstance->setStackInstance($stackInstance);
-
- // Get a crypto instance ...
- $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
-
- // ... and set it in this handler
- $handlerInstance->setCryptoInstance($cryptoInstance);
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Initializes the handler
- *
- * @return void
- */
- private function initHandler () {
- // Noisy debug line:
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Initializing handler ...');
-
- // Init finalPackageChunks
- $this->finalPackageChunks = array(
- // Array for package content
- 'content' => array(),
- // ... and for the hashes
- 'hashes' => array(),
- // ... marker for that the final array is complete for assembling all chunks
- 'is_complete' => FALSE,
- // ... steps done to assemble all chunks
- 'assemble_steps' => 0,
- );
-
- // ... chunkHashes:
- $this->chunkHashes = array();
-
- // ... eopChunk:
- $this->eopChunk = array(
- 0 => 'INVALID',
- 1 => 'INVALID',
- );
- }
-
- /**
- * Checks whether the hash generated from package content is the same ("valid") as given
- *
- * @param $chunkSplits An array from a splitted chunk
- * @return $isValid Whether the hash is "valid"
- */
- private function isChunkHashValid (array $chunkSplits) {
- // Noisy debug line:
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: chunkSplits=' . print_r($chunkSplits, TRUE));
-
- // Assert on some elements
- assert(isset($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA]));
- assert(isset($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]));
-
- // Now hash the raw data again
- $chunkHash = $this->getCryptoInstance()->hashString($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA], $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH], FALSE);
-
- // Check it
- $isValid = ($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] === $chunkHash);
-
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: chunkHash=' . $chunkHash . ',isValid=' . intval($isValid));
-
- // ... and return it
- return $isValid;
- }
-
- /**
- * Checks whether the given serial number is valid
- *
- * @param $serialNumber A serial number from a chunk
- * @return $isValid Whether the serial number is valid
- */
- private function isSerialNumberValid ($serialNumber) {
- // Check it
- $isValid = ((strlen($serialNumber) == PackageFragmenter::MAX_SERIAL_LENGTH) && ($this->hexval($serialNumber, FALSE) === $serialNumber));
-
- // Return result
- return $isValid;
- }
-
- /**
- * Adds the chunk to the final array which will be used for the final step
- * which will be to assemble all chunks back to the original package content
- * and for the final hash check.
- *
- * This method may throw an exception if a chunk with the same serial number
- * has already been added to avoid mixing chunks from different packages.
- *
- * @param $chunkSplits An array from a splitted chunk
- * @return void
- */
- private function addChunkToFinalArray (array $chunkSplits) {
- // Is the serial number (index 1) already been added?
- if (isset($this->finalPackageChunks[$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]])) {
- // Then throw an exception
- throw new ChunkAlreadyAssembledException(array($this, $chunkSplits), self::EXCEPTION_CHUNK_ALREADY_ASSEMBLED);
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: serialNumber=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ',hash=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]);
-
- // Add the chunk data (index 2) to the final array and use the serial number as index
- $this->finalPackageChunks['content'][$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]] = $chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA];
-
- // ... and the hash as well
- $this->finalPackageChunks['hashes'][$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]] = $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH];
- }
-
- /**
- * Marks the final array as completed, do only this if you really have all
- * chunks together including EOP and "hash chunk".
- *
- * @return void
- */
- private function markFinalArrayAsCompleted () {
- /*
- * As for now, just set the array element. If any further steps are
- * being added, this should always be the last step.
- */
- $this->finalPackageChunks['is_complete'] = TRUE;
- }
-
- /**
- * Sorts the chunks array by using the serial number as a sorting key. In
- * most situations a call of ksort() is enough to accomblish this. So this
- * method may only call ksort() on the chunks array.
- *
- * This method sorts 'content' and 'hashes' so both must have used the
- * serial numbers as array indexes.
- *
- * @return void
- */
- private function sortChunksArray () {
- // Sort 'content' first
- ksort($this->finalPackageChunks['content']);
-
- // ... then 'hashes'
- ksort($this->finalPackageChunks['hashes']);
- }
-
- /**
- * Prepares the package assemble by removing last chunks (last shall be
- * hash chunk, pre-last shall be EOP chunk) and verify that all serial
- * numbers are valid (same as PackageFragmenter class would generate).
- *
- * @return void
- */
- private function preparePackageAssmble () {
- // Make sure both arrays have same count (this however should always be TRUE)
- assert(count($this->finalPackageChunks['hashes']) == count($this->finalPackageChunks['content']));
- //* DIE: */ exit(__METHOD__ . ':finalPackageChunks='.print_r($this->finalPackageChunks['content'], TRUE));
-
- /*
- * Remove last element (hash chunk) from 'hashes'. This hash will never
- * be needed, so ignore it.
- */
- array_pop($this->finalPackageChunks['hashes']);
-
- // ... and from 'content' as well but save it for later use
- $this->chunkHashes = explode(PackageFragmenter::CHUNK_HASH_SEPARATOR, substr(array_pop($this->finalPackageChunks['content']), strlen(PackageFragmenter::HASH_CHUNK_IDENTIFIER)));
-
- // Remove EOP chunk and keep a copy of it
- array_pop($this->finalPackageChunks['hashes']);
- $this->eopChunk = explode(PackageFragmenter::CHUNK_HASH_SEPARATOR, substr(array_pop($this->finalPackageChunks['content']), strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)));
-
- // Verify all serial numbers
- $this->verifyChunkSerialNumbers();
- }
-
- /**
- * Verifies all chunk serial numbers by using a freshly initialized
- * fragmenter instance. Do ALWAYS sort the array and array_pop() the hash
- * chunk before calling this method to avoid re-requests of many chunks.
- *
- * @return void
- */
- private function verifyChunkSerialNumbers () {
- // Debug message
- //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: finalPackageChunks=' . print_r($this->finalPackageChunks, TRUE));
-
- // Get final hash
- $finalHash = $this->generateFinalHash(implode('', $this->finalPackageChunks['content']));
-
- // Reset the serial number generator
- $this->fragmenterInstance->resetSerialNumber($finalHash);
-
- // "Walk" through all (content) chunks
- foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) {
- // Get next serial number
- $nextSerial = $this->fragmenterInstance->getNextHexSerialNumber($finalHash);
-
- // Debug output
- //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: serialNumber=' . $serialNumber . ',nextSerial=' . $nextSerial);
-
- // Is it not the same? Then re-request it
- if ($serialNumber != $nextSerial) {
- // This is invalid, so remove it
- unset($this->finalPackageChunks['content'][$serialNumber]);
- unset($this->finalPackageChunks['hashes'][$serialNumber]);
-
- // And re-request it with valid serial number (and hash chunk)
- $this->rerequestChunkBySerialNumber($nextSerial);
- } // END - if
- } // END - foreach
- }
-
- /**
- * Assembles and verifies ("final check") chunks back together to the
- * original package (raw data for the start). This method should only be
- * called AFTER the EOP and final-chunk chunk have been removed.
- *
- * @return void
- */
- private function assembleAllChunksToPackage () {
- // If chunkHashes is not filled, don't continue
- assert(count($this->chunkHashes) > 0);
-
- // Init raw package data string
- $this->rawPackageData = '';
-
- // That went well, so start assembling all chunks
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Handling ' . count($this->finalPackageChunks['content']) . ' entries ...');
- foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) {
- // Assert on 'hash' entry (must always be set)
- assert(isset($this->finalPackageChunks['hashes'][$serialNumber]));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: serialNumber=' . $serialNumber . ',hashes=' . $this->finalPackageChunks['hashes'][$serialNumber] . ' - validating ...');
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('finalPackageChunks=' . print_r($this->finalPackageChunks, TRUE) . 'chunkHashes=' . print_r($this->chunkHashes, TRUE));
-
- // Is this chunk valid? This should be the case
- assert($this->isChunkHashValid(array(
- self::CHUNK_SPLITS_INDEX_HASH => $this->finalPackageChunks['hashes'][$serialNumber],
- self::CHUNK_SPLITS_INDEX_RAW_DATA => $content
- )));
-
- // ... and is also in the hash chunk?
- assert(in_array($this->finalPackageChunks['hashes'][$serialNumber], $this->chunkHashes));
-
- // Verification okay, add it to the raw data
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Adding ' . strlen($content) . ' bytes as raw package data ...');
- $this->rawPackageData .= $content;
- } // END - foreach
-
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: eopChunk[1]=' . $this->eopChunk[1] . ',index=' . (count($this->chunkHashes) - 2) . ',chunkHashes='.print_r($this->chunkHashes, TRUE));
-
- // The last chunk hash must match with the one from eopChunk[1]
- assert($this->eopChunk[1] == $this->chunkHashes[count($this->chunkHashes) - 2]);
- }
-
- /**
- * Generate final hash if EOP chunk is found, else an assert will happen.
- *
- * @param $rawPackageData Raw package data
- * @return $finalHash Final hash if EOP chunk is found
- */
- private function generateFinalHash ($rawPackageData) {
- // Make sure the raw package data is given
- assert((is_string($rawPackageData)) && (!empty($rawPackageData)));
-
- // Make sure the EOP chunk is set
- assert((isset($this->eopChunk[0])) && (isset($this->eopChunk[1])));
- assert((is_string($this->eopChunk[0])) && (!empty($this->eopChunk[0])));
-
- // Hash the raw data
- $finalHash = $this->getCryptoInstance()->hashString($rawPackageData, $this->eopChunk[0], FALSE);
-
- // Return it
- return $finalHash;
- }
-
- /**
- * Verifies the finally assembled raw package data by comparing it against
- * the final hash.
- *
- * @return void
- */
- private function verifyRawPackageData () {
- // Generate final hash
- $finalHash = $this->generateFinalHash($this->rawPackageData);
-
- // Is it the same?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: eopChunk[1]=' . $this->eopChunk[1] . ',finalHash=' . $finalHash);
- assert($finalHash == $this->eopChunk[0]);
- }
-
- /**
- * Checks whether the final (last) chunk is valid
- *
- * @param $chunks An array with chunks and (hopefully) a valid final chunk
- * @return $isValid Whether the final (last) chunk is valid
- */
- private function isValidFinalChunk (array $chunks) {
- // Default is all fine
- $isValid = TRUE;
-
- // Split the (possible) EOP chunk
- $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunks[count($chunks) - 1]);
-
- // Make sure chunks with only 3 elements are parsed (for details see ChunkHandler)
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('eopChunk=' . $chunks[count($chunks) - 1] . ',chunkSplits=' . print_r($chunkSplits, TRUE));
- assert(count($chunkSplits) == 3);
-
- // Validate final chunk
- if (substr($chunkSplits[ChunkHandler::CHUNK_SPLITS_INDEX_RAW_DATA], 0, strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)) != PackageFragmenter::END_OF_PACKAGE_IDENTIFIER) {
- // Not fine
- $isValid = FALSE;
- } elseif (substr_count($chunkSplits[ChunkHandler::CHUNK_SPLITS_INDEX_RAW_DATA], PackageFragmenter::CHUNK_HASH_SEPARATOR) != 1) {
- // CHUNK_HASH_SEPARATOR shall only be found once
- $isValid = FALSE;
- }
-
- // Return status
- return $isValid;
- }
-
- /**
- * Adds all chunks if the last one verifies as a 'final chunk'.
- *
- * @param $chunks An array with chunks, the last one should be a 'final'
- * @return void
- * @throws FinalChunkVerificationException If the final chunk does not start with 'EOP:'
- */
- public function addAllChunksWithFinal (array $chunks) {
- // Try to validate the final chunk
- try {
- // Validate final chunk
- $this->isValidFinalChunk($chunks);
- } catch (AssertionException $e) {
- // Last chunk is not valid
- throw new FinalChunkVerificationException(array($this, $chunks, $e), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION);
- }
-
- // Do we have some pending chunks (no final)?
- while (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL)) {
- // Then get it first and add it before the EOP chunks
- array_unshift($chunks, $this->getStackInstance()->popNamed(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL));
- } // END - while
-
- // Add all chunks to the FIFO stacker
- foreach ($chunks as $chunk) {
- // Add the chunk
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP, $chunk);
- } // END - foreach
- }
-
- /**
- * Adds all chunks and wait for more (e.g. incomplete transmission)
- *
- * @param $chunks An array with chunks, the last one should be a 'final'
- * @return void
- */
- public function addAllChunksWait (array $chunks) {
- // Add all chunks to the FIFO stacker
- foreach ($chunks as $chunk) {
- // Add the chunk
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL, $chunk);
- } // END - foreach
- }
-
- /**
- * Checks whether unhandled chunks are available
- *
- * @return $unhandledChunks Whether unhandled chunks are left
- */
- public function ifUnhandledChunksWithFinalAvailable () {
- // Simply check if the stacker is not empty
- $unhandledChunks = $this->getStackInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP) === FALSE;
-
- // Return result
- return $unhandledChunks;
- }
-
- /**
- * Handles available chunks by processing one-by-one (not all together,
- * this would slow-down the whole application) with the help of an
- * iterator.
- *
- * @return void
- */
- public function handleAvailableChunksWithFinal () {
- // First check if there are undhandled chunks available
- assert($this->ifUnhandledChunksWithFinalAvailable());
-
- // Get an entry from the stacker
- $chunk = $this->getStackInstance()->popNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP);
-
- // Split the string with proper separator character
- $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunk);
-
- /*
- * Make sure three elements are always found:
- * 0 = Hash
- * 1 = Serial number
- * 2 = Raw data
- */
- assert(count($chunkSplits) == 3);
-
- // Is the generated hash from data same ("valid") as given hash?
- if (!$this->isChunkHashValid($chunkSplits)) {
- // Do some logging
- self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Chunk content is not validating against given hash.');
-
- // Re-request this chunk (trust the hash in index # 0)
- $this->rerequestChunkBySplitsArray($chunkSplits);
-
- // Don't process this chunk
- return;
- } // END - if
-
- // Is the serial number valid (chars 0-9, length equals PackageFragmenter::MAX_SERIAL_LENGTH)?
- if (!$this->isSerialNumberValid($chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL])) {
- // Do some logging
- self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Chunk serial number ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ' for hash ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] . ' is invalid.');
-
- // Re-request this chunk
- $this->rerequestChunkBySplitsArray($chunkSplits);
-
- // Don't process this chunk
- return;
- } // END - if
-
- /*
- * It is now known that (as long as the hash algorithm has no
- * collisions) the content is the same as the sender sends it to this
- * peer.
- *
- * And also the serial number is valid (basicly) at this point. Now the
- * chunk can be added to the final array.
- */
- $this->addChunkToFinalArray($chunkSplits);
-
- // Is the stack now empty?
- if ($this->getStackInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP)) {
- // Then mark the final array as complete
- $this->markFinalArrayAsCompleted();
- } // END - if
- }
-
- /**
- * Checks whether unassembled chunks are available (ready) in final array
- *
- * @return $unassembledChunksAvailable Whether unassembled chunks are available
- */
- public function ifUnassembledChunksAvailable () {
- // For now do only check the array element 'is_complete'
- $unassembledChunksAvailable = ($this->finalPackageChunks['is_complete'] === TRUE);
-
- // Return status
- return $unassembledChunksAvailable;
- }
-
- /**
- * Assembles all chunks (except EOP and "hash chunk") back together to the original package data.
- *
- * This is done by the following steps:
- *
- * 1) Sort the final array with ksort(). This will bring the "hash
- * chunk" up to the last array index and the EOP chunk to the
- * pre-last array index
- * 2) Assemble all chunks except two last (see above step)
- * 3) While so, do the final check on all hashes
- * 4) If the package is assembled back together, hash it again for
- * the very final verification.
- *
- * @return void
- */
- public function assembleChunksFromFinalArray () {
- // Make sure the final array is really completed
- assert($this->ifUnassembledChunksAvailable());
-
- // Count up stepping
- $this->finalPackageChunks['assemble_steps']++;
-
- // Do the next step
- switch ($this->finalPackageChunks['assemble_steps']) {
- case 1: // Sort the chunks array (the serial number shall act as a sorting key)
- $this->sortChunksArray();
- break;
-
- case 2: // Prepare the assemble by removing last two indexes
- $this->preparePackageAssmble();
- break;
-
- case 3: // Assemble all chunks back together to the original package
- $this->assembleAllChunksToPackage();
- break;
-
- case 4: // Verify the raw data by hashing it again
- $this->verifyRawPackageData();
- break;
-
- case 5: // Re-initialize handler to reset it to the old state
- $this->initHandler();
- break;
-
- default: // Invalid step found
- self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Invalid step ' . $this->finalPackageChunks['assemble_steps'] . ' detected.');
- break;
- } // END - switch
- }
-
- /**
- * Checks whether the raw package data has been assembled back together.
- * This can be safely assumed when rawPackageData is not empty and the
- * collection of all chunks is FALSE (because initHandler() will reset it).
- *
- * @return $isRawPackageDataAvailable Whether raw package data is available
- */
- public function ifRawPackageDataIsAvailable () {
- // Check it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: this->rawPackageData()=' . strlen($this->rawPackageData) . ',ifUnassembledChunksAvailable()=' . intval($this->ifUnassembledChunksAvailable()));
- $isRawPackageDataAvailable = ((!empty($this->rawPackageData)) && (!$this->ifUnassembledChunksAvailable()));
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: isRawPackageDataAvailable=' . intval($isRawPackageDataAvailable));
- return $isRawPackageDataAvailable;
- }
-
- /**
- * Handles the finally assembled raw package data by feeding it into another
- * stacker for further decoding/processing.
- *
- * @return void
- */
- public function handledAssembledRawPackageData () {
- // Assert to make sure that there is raw package data available
- assert($this->ifRawPackageDataIsAvailable());
-
- // Then feed it into the next stacker
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CHUNK-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Pushing ' . strlen($this->rawPackageData) . ' bytes to stack ' . self::STACKER_NAME_ASSEMBLED_RAW_DATA . ' ...');
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_ASSEMBLED_RAW_DATA, $this->rawPackageData);
-
- // ... and reset it
- $this->rawPackageData = '';
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-<?php
-/**
- * A general data Handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
- */
-abstract class BaseDataHandler extends BaseHandler {
- /**
- * Last exception instance from database layer or NULL (default)
- */
- private $lastException = NULL;
-
- /**
- * Array with search criteria elements
- */
- protected $searchData = array();
-
- /**
- * Array with all data XML nodes (which hold the actual data) and their values
- */
- protected $messageDataElements = array();
-
- /**
- * Array for translating message data elements (other node's data mostly)
- * into configuration elements.
- */
- protected $messageToConfig = array();
-
- /**
- * Array for copying configuration entries
- */
- protected $configCopy = array();
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set it here
- $this->setDhtInstance($dhtInstance);
- }
-
- /**
- * Getter for search data array
- *
- * @return $searchData Search data array
- */
- public final function getSearchData () {
- return $this->searchData;
- }
-
- /**
- * Getter for last exception
- *
- * @return $lastException Last thrown exception
- */
- public final function getLastException () {
- return $this->lastException;
- }
-
- /**
- * Setter for last exception
- *
- * @param $lastException Last thrown exception
- * @return void
- */
- public final function setLastException (FrameworkException $exceptionInstance = NULL) {
- $this->lastException = $exceptionInstance;
- }
-
- /**
- * Prepares a message as answer for given message data for delivery.
- *
- * @param $messageData An array with all message data
- * @param $packageInstance An instance of a Deliverable instance
- * @return void
- */
- protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send an answer message for ' . $this->getHandlerName() . ' ...');
-
- // Get a helper instance based on this handler's name
- $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData));
-
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Load descriptor XML
- $helperInstance->loadDescriptorXml($nodeInstance);
-
- /*
- * Set missing (temporary) configuration data, mostly it needs to be
- * copied from message data array.
- */
- $this->initMessageConfigurationData($messageData);
-
- // Compile any configuration variables
- $helperInstance->getTemplateInstance()->compileConfigInVariables();
-
- // Deliver the package
- $helperInstance->sendPackage($nodeInstance);
-
- /*
- * Remove temporary configuration
- */
- $this->removeMessageConfigurationData($messageData);
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Answer message has been prepared.');
- }
-
- /**
- * Prepares the next message
- *
- * @param $messageData An array with all message data
- * @param $packageInstance An instance of a Deliverable instance
- * @return void
- */
- protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send next message ...');
-
- // Get a helper instance based on this handler's name
- $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
-
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Load descriptor XML
- $helperInstance->loadDescriptorXml($nodeInstance);
-
- /*
- * Set missing (temporary) configuration data, mostly it needs to be
- * copied from message data array.
- */
- $this->initMessageConfigurationData($messageData);
-
- // Compile any configuration variables
- $helperInstance->getTemplateInstance()->compileConfigInVariables();
-
- // Deliver the package
- $helperInstance->sendPackage($nodeInstance);
-
- /*
- * Remove temporary configuration
- */
- $this->removeMessageConfigurationData($messageData);
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Next message has been prepared.');
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- abstract protected function initMessageConfigurationData (array $messageData);
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- abstract protected function removeMessageConfigurationData (array $messageData);
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A NodeMessageAnnouncement handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageAnnouncementHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_announcement');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID => 'your_node_id',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash',
- );
-
- // Init config-copy array
- $this->configCopy = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash',
- );
-
- // Init array
- $this->searchData = array(
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageAnnouncementHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageAnnouncementHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws AnnouncementNotAcceptedException If this node does not accept announcements
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Is this node accepting announcements?
- if (!$nodeInstance->isAcceptingAnnouncements()) {
- /*
- * This node is not accepting announcements, then someone wants to
- * announce his node to a non-bootstrap and non-master node.
- */
- throw new AnnouncementNotAcceptedException(array($this, $nodeInstance, $messageData), BaseHubSystem::EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED);
- } // END - if
-
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Prepare answer message to be delivered back to the other node
- $this->prepareAnswerMessage($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- // Add it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Adding messageData[' . $key . ']=' . $messageData[$key] . ' ...');
- $dataSetInstance->addCriteria($key, $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
-
- // "Walk" throught the translation array
- foreach ($this->messageToConfig as $messageKey => $configKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]);
-
- // Set the element in configuration
- $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]);
- } // END - foreach
-
- // "Walk" throught the config-copy array
- foreach ($this->configCopy as $targetKey => $sourceKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANNOUNCEMENT-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
-
- // Copy from source to targetKey
- $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
- } // END - foreach
-
- // Translate last exception into a status code
- $statusCode = $this->getTranslatedStatusFromLastException();
-
- // Set it in configuration (temporarily)
- $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // "Walk" throught the translation array again
- foreach ($this->messageToConfig as $dummy => $configKey) {
- // Now unset this configuration entry (to save some memory)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // "Walk" throught the config-copy array again
- foreach ($this->configCopy as $configKey => $dummy) {
- // Now unset this configuration entry (to save some memory again)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // Remove NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS as well
- $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A NodeMessageAnnouncementAnswer handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_announcement_answer');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
- BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- /*
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id'
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash'
- */
- );
-
- // Init config-copy array
- $this->configCopy = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
- XmlAnnouncementAnswerTemplateEngine::OAANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
- XmlAnnouncementAnswerTemplateEngine::OAANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash',
- );
-
- // Init array
- $this->searchData = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageAnnouncementAnswerHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageAnnouncementAnswerHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws NoAnnouncementAttemptedException If this node has not attempted to announce itself
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Has this node attempted to announce itself?
- if (!$nodeInstance->ifNodeIsAnnouncing()) {
- /*
- * This node has never announced itself, so it doesn't expect
- * announcement answer messages.
- */
- throw new NoAnnouncementAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
- } // END - if
-
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Handle the answer status element
- $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- /*
- * Add it, but remove any 'my-' prefixes as they are not used in
- * database layer.
- */
- $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A NodeMessageDhtBootstrapAnswer handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageDhtBootstrapAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_announcement_answer');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
- BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- /*
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id'
- */
- );
-
- // Init config-copy array
- $this->configCopy = array(
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
- );
-
- // Init array
- $this->searchData = array(
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageDhtBootstrapAnswerHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageDhtBootstrapAnswerHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws NoDhtBootstrapAttemptedException If this DHT has not attempted to bootstrap
- * @todo ~30% done
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Has this DHT attempted to bootstrap?
- if (!$dhtInstance->ifDhtIsBooting()) {
- /*
- * This DHT has never bootstrapped, so it doesn't expect
- * announcement answer messages.
- */
- throw new NoDhtBootstrapAttemptedException(array($this, $dhtInstance, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED);
- } // END - if
-
- // Unfinished
- $this->partialStub('UNHANDLED: messageData=' . print_r($messageData, TRUE));
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- /*
- * Add it, but remove any 'my-' prefixes as they are not used in
- * database layer.
- */
- $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A NodeMessageRequestNodeListAnswer handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_request_node_list_answer');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
- BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- /*
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
- */
- );
-
- // Init search data array
- $this->searchData = array(
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageRequestNodeListAnswerHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Has this node attempted to announce itself?
- if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
- /*
- * This node has never announced itself, so it doesn't expect
- * request-node-list answer messages.
- */
- throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
- } // END - if
-
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Handle the answer status element
- $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANSWER-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData[' . $key . ']=' . $messageData[$key]);
-
- // Is it there?
- assert(isset($messageData[$key]));
-
- /*
- * Add it, but remove any 'my-' prefixes as they are not used in
- * database layer.
- */
- $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A NodeMessage??? handler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 NodeMessage???Handler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_===');
-
- // Init message data array
- $this->messageDataElements = array(
- Xml???TemplateEngine::!!!_DATA_EXTERNAL_ADDRESS,
- Xml???TemplateEngine::!!!_DATA_NODE_STATUS,
- Xml???TemplateEngine::!!!_DATA_SESSION_ID,
- Xml???TemplateEngine::!!!_DATA_LISTEN_PORT,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessage???Handler () {
- // Get new instance
- $handlerInstance = new NodeMessage???Handler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Prepare answer message to be delivered back to the other node
- $this->prepareAnswerMessage($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- // Add it
- $dataSetInstance->addCriteria($key, $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general message handler, this class must be abstract to make the template
- * method pattern working.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
- */
-abstract class BaseMessageHandler extends BaseDataHandler {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * "Getter" for a translated last exception as a status code
- *
- * @return $statusCode Translated status code from last exception
- */
- protected function getTranslatedStatusFromLastException () {
- // Default is all fine
- $statusCode = BaseHubSystem::MESSAGE_STATUS_CODE_OKAY;
-
- // Is the last exception not NULL?
- if ($this->getLastException() instanceof FrameworkException) {
- // "Determine" the right status code (may differ from exception to exception)
- $this->debugInstance('lastException=' . $this->getLastException()->__toString() . ',message=' . $this->getLastException()->getMessage() . ' is not finished!');
- } // END - if
-
- // Return the status code
- return $statusCode;
- }
-
- /**
- * Registers an other node with this node by given message data. The
- * following data must always be present:
- *
- * - session-id (for finding the node's record together with below data)
- * - external-address (hostname or IP number)
- * - listen-port (TCP/UDP listen port for inbound connections)
- *
- * @param $messageArray An array with all minimum message data
- * @return void
- */
- protected function registerNodeByMessageData (array $messageData) {
- // Check if searchData has entries
- assert(count($this->getSearchData()) > 0);
-
- // Let the DHT facade do the work
- $this->getDhtInstance()->registerNodeByMessageData($messageData, $this);
- }
-
- /**
- * Posty-handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function postHandleMessageData (array $messageData, Receivable $packageInstance) {
- /*
- * Feed hash to miner by handling over the whole array as also the
- * sender and tags are needed.
- */
- $packageInstance->feedHashToMiner($messageData);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A NodeMessageDhtBootstrap handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_dht_bootstrap');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id'
- );
-
- // Init config-copy array
- $this->configCopy = array(
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
- );
-
- // Init array
- $this->searchData = array(
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageDhtBootstrapHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageDhtBootstrapHandler();
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set the DHT instance here
- $handlerInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws DhtBootstrapNotAcceptedException If this node does not accept DHT bootstrap requests
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Is this node accepting DHT bootstrap requests?
- if (!NodeObjectFactory::createNodeInstance()->isAcceptingDhtBootstrap()) {
- /*
- * This node is not accepting DHT bootstrap requests.
- */
- throw new DhtBootstrapNotAcceptedException(array($this, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED);
- } // END - if
-
- // Register the DHT bootstrap requesting node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Prepare answer message to be delivered back to the other node
- $this->prepareAnswerMessage($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- // Add it
- $dataSetInstance->addCriteria($key, $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-BOOTSTRAP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
-
- // "Walk" throught the translation array
- foreach ($this->messageToConfig as $messageKey => $configKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-BOOTSTRAP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]);
-
- // Set the element in configuration
- $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]);
- } // END - foreach
-
- // "Walk" throught the config-copy array
- foreach ($this->configCopy as $targetKey => $sourceKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-BOOTSTRAP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
-
- // Copy from source to target key
- $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
- } // END - foreach
-
- // Translate last exception into a status code
- $statusCode = $this->getTranslatedStatusFromLastException();
-
- // Set it in configuration (temporarily)
- $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
-
- /*
- * Use the DHT instance to get a list of recipients. This means that all
- * DHT nodes that accept bootstrap requests are read from the DHT
- * database.
- */
- $nodeList = $this->getDhtInstance()->findRecipientsByKey(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPT_BOOTSTRAP, 'Y');
-
- // Make sure it is an array and has at least one entry
- assert(is_array($nodeList));
- assert(count($nodeList) > 0);
-
- // Set it in configuration
- $this->getConfigInstance()->setConfigEntry('dht_nodes', base64_encode(json_encode($nodeList)));
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // "Walk" throught the translation array again
- foreach ($this->messageToConfig as $dummy => $configKey) {
- // Now unset this configuration entry (to save some memory)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // "Walk" throught the config-copy array again
- foreach ($this->configCopy as $configKey => $dummy) {
- // Now unset this configuration entry (to save some memory again)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // Remove temporary "special" values as well
- $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
- $this->getConfigInstance()->unsetConfigEntry('dht_nodes');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A NodeMessageRequestNodeList handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageRequestNodeListHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_request_node_list');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
- );
-
- // Init config-copy array
- $this->configCopy = array(
- );
-
- // Init search data array
- $this->searchData = array(
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageRequestNodeListHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageRequestNodeListHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws RequestNotAcceptedException If this node does not accept this request
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Is this node accepting announcements?
- if (!$nodeInstance->isAcceptingNodeListRequests()) {
- /*
- * This node is not accepting node list requests. Throw an
- * exception to abort any further processing.
- */
- throw new RequestNotAcceptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_REQUEST_NOT_ACCEPTED);
- } // END - if
-
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Prepare answer message to be delivered back to the other node
- $this->prepareAnswerMessage($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- // Add it
- $dataSetInstance->addCriteria($key, $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REQUEST-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
-
- // "Walk" throught the config-copy array
- foreach ($this->configCopy as $targetKey => $sourceKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REQUEST-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
-
- // Copy from source to targetKey
- $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
- } // END - foreach
-
- // Query local DHT for nodes except given session id
- $nodeList = $this->getDhtInstance()->queryLocalNodeListExceptByMessageData(
- $messageData,
- $this,
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
- BaseHubNode::OBJECT_LIST_SEPARATOR
- );
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REQUEST-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Got a node list of ' . count($nodeList) . ' entry/-ies back.');
-
- // Set it serialized in configuration (temporarily)
- $this->getConfigInstance()->setConfigEntry('node_list', base64_encode(json_encode($nodeList)));
-
- // Translate last exception into a status code
- $statusCode = $this->getTranslatedStatusFromLastException();
-
- // Set it in configuration (temporarily)
- $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // "Walk" throught the config-copy array again
- foreach ($this->configCopy as $configKey => $dummy) {
- // Now unset this configuration entry (to save some memory again)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // Remove answer status/node list as well
- $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
- $this->getConfigInstance()->unsetConfigEntry('node_list');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A NodeMessageSelfConnect handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_self_connect');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageSelfConnectHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageSelfConnectHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Are node id and session id the same?
- if (($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID] == $nodeInstance->getNodeId()) && ($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID] == $nodeInstance->getSessionId())) {
- // Both are equal
- self::createDebugInstance(__CLASS__)->debugOutput('SELF-CONNECT[' . __METHOD__ . ':' . __LINE__ . ']: Have connected to myself, both node and session id are equal!');
-
- // ... and change state
- $nodeInstance->getStateInstance()->nodeHasSelfConnected();
- } else {
- // Something really horrible happened
- // @TODO Throw an exception here instead of dying
- $this->debugInstance(__METHOD__ . ': ids mismatching! messageData=' . print_r($messageData, TRUE));
- }
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Please don't call this method!
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Please don't call this method!
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Removes configuration data with given message data array from global configuration
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Please don't call this method!
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-<?php
-/**
- * A general Handler for raw data from sockets
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseRawDataHandler extends BaseHandler {
- // Error codes:
- // - Socket raw data stream errors
- const SOCKET_ERROR_UNKNOWN = 'unknown_error'; // Unknown error (should not happen)
- const SOCKET_ERROR_TRANSPORT_ENDPOINT = 'transport_endpoint'; // Transport endpoint has closed
- const SOCKET_ERROR_INVALID_BASE64_MODULO = 'base64_modulo'; // Length is not modulo 4
- const SOCKET_ERROR_INVALID_BASE64_MESSAGE = 'base64_message'; // Raw data is not Base64-encoded
- const SOCKET_ERROR_UNHANDLED = 'unhandled_package'; // Unhandled raw data (not bad)
- const SOCKET_ERROR_CONNECTION_REFUSED = 'connection_refused'; // The name says it: connection refused
- const SOCKET_ERROR_CONNECTION_TIMED_OUT = 'connection_timed_out'; // The name says it: connection attempt has timed-out
- const SOCKET_ERROR_OPERATION_IN_PROGRESS = 'operation_in_progress'; // 'Operation now in progress'
- const SOCKET_ERROR_OPERATION_ALREADY_PROGRESS = 'operation_already_progress'; // 'Operation already in progress'
- const SOCKET_ERROR_RESOURCE_UNAVAILABLE = 'resource_unavailable'; // 'Resource temporary unavailable'
- const SOCKET_ERROR_NO_ROUTE_TO_HOST = 'no_route_to_host'; // The name says it: no route to host
- const SOCKET_ERROR_CONNECTION_RESET_BY_PEER = 'connection_reset_by_peer'; // Connection reset by peer
- const SOCKET_ERROR_BROKEN_PIPE = 'broken_pipe'; // Broken pipe
- const SOCKET_CONNECTED = 'connected'; // Nothing errorous happens, socket is connected
-
- // - Package errors
- const PACKAGE_ERROR_INVALID_DATA = 'invalid_data'; // Invalid data in package found
- const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
- const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content'; // Content is invalid (e.g. not well-formed)
- const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
- const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package'; // Package is fine
-
- // Package data
- const PACKAGE_RAW_DATA = 'raw_data';
- const PACKAGE_ERROR_CODE = 'error_code';
-
- // Start/end marker
- const STREAM_START_MARKER = '[[S]]';
- const STREAM_END_MARKER = '[[E]]';
-
- /**
- * Stacker for raw data
- */
- const STACKER_NAME_RAW_DATA = 'raw_data';
-
- /**
- * Error code from socket
- */
- private $errorCode = -1;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Set error code to 'unknown'
- $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
-
- // Init stacker instance for processed raw data
- $stackInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
-
- // Remember this in this package handler
- $this->setStackInstance($stackInstance);
-
- // Init stacker
- $this->initStack();
- }
-
- /**
- * Initializes the stacker for raw data
- *
- * @return void
- */
- protected function initStack () {
- $this->getStackInstance()->initStack(self::STACKER_NAME_RAW_DATA);
- }
-
- /**
- * Adds given raw data to the raw data stacker
- *
- * @param $rawData raw data from the socket resource
- * @return void
- */
- protected function addRawDataToStacker ($rawData) {
- /*
- * Add the deocoded data and error code to the stacker so other classes
- * (e.g. NetworkPackage) can "pop" it from the stacker.
- */
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_RAW_DATA, array(
- self::PACKAGE_RAW_DATA => $rawData,
- self::PACKAGE_ERROR_CODE => $this->getErrorCode()
- ));
- }
-
- /**
- * Checks whether raw data is pending for further processing.
- *
- * @return $isPending Whether raw data is pending
- */
- public function isRawDataPending () {
- // Does the stacker have some entries (not empty)?
- $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_RAW_DATA));
-
- // Return it
- return $isPending;
- }
-
- /**
- * "Getter" for next raw data from the stacker
- *
- * @return $rawData Raw data from the stacker
- */
- public function getNextRawData () {
- // "Pop" the raw data from the stacker
- $rawData = $this->getStackInstance()->popNamed(self::STACKER_NAME_RAW_DATA);
-
- // And return it
- return $rawData;
- }
-
- /**
- * Checks whether the 'recipient' field matches our own an universal node
- * locator.
- *
- * @param $packageData Raw package data
- * @return $matches Whether it matches
- * @todo This method will be moved to a better place
- */
- protected function ifRecipientMatchesOwnUniversalNodeLocator (array $packageData) {
- // Construct own address first
- $ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator();
-
- // Does it match?
- $matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
- // Return result
- return $matches;
- }
-
- /**
- * Setter for error code
- *
- * @param $errorCode The error code we shall set
- * @return void
- */
- public final function setErrorCode ($errorCode) {
- $this->errorCode = $errorCode;
- }
-
- /**
- * Getter for error code
- *
- * @return $errorCode The error code
- */
- public final function getErrorCode () {
- return $this->errorCode;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-while (count($clients) > 0) {
- // create a copy, so $clients doesn't get modified by socket_select()
- $read = $clients;
-
- // get a list of all the clients that have data to be read from
- // if there are no clients with data, go to next iteration
- $left = @socket_select($read, $write = null, $except = null, 0, 150);
- if ($left < 1) {
- continue;
- }
-
- // check if there is a client trying to connect
- if (in_array($mainSocket, $read)) {
- // accept the client, and add him to the $clients array
- $new_sock = socket_accept($mainSocket);
- $clients[] = $new_sock;
-
- // send the client a welcome message
- socket_write($new_sock, "No noobs, but I'll make an exception. :)\n".
- "There are ".(count($clients) - 1)." client(s) connected to the server.\n");
-
- socket_getpeername($new_sock, $ip);
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:New client connected: {$ip}");
-
- // Notify all chatter
- if (count($clients) > 2) {
- foreach ($clients as $send_sock) {
- if ($send_sock != $mainSocket && $send_sock != $new_sock) {
- socket_write($send_sock, "Server: Chatter has joined from {$ip}. There are now ".(count($clients) - 1)." clients.\n");
- }
- }
- }
-
- // remove the listening socket from the clients-with-data array
- $key = array_search($mainSocket, $read);
- unset($read[$key]);
- }
-
- // loop through all the clients that have data to read from
- foreach ($read as $read_sock) {
- // Get client data
- socket_getpeername($read_sock, $ip);
-
- // read until newline or 1024 bytes
- // socket_read while show errors when the client is disconnected, so silence the error messages
- $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ);
-
- // check if the client is disconnected
- if (($data === FALSE) || (in_array(strtolower(trim($data)), $leaving))) {
-
- // remove client for $clients array
- $key = array_search($read_sock, $clients);
- unset($clients[$key]);
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client from {$ip} disconnected. Left: ".(count($clients) - 1)."");
-
- // Notify all chatter
- if (count($clients) > 1) {
- foreach ($clients as $send_sock) {
- if ($send_sock != $mainSocket) {
- socket_write($send_sock, "Server: Chatter from {$ip} has logged out. ".(count($clients) - 1)." client(s) left.\n");
- }
- }
- }
-
- // continue to the next client to read from, if any
- socket_write($read_sock, "Server: Good bye.\n");
- socket_shutdown($read_sock, 2);
- socket_close($read_sock);
- continue;
- } elseif (in_array(trim($data), $shutdown)) {
- // Is he allowed to shutdown?
- if (!in_array($ip, $masters)) {
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has tried to shutdown the server!");
- socket_write($read_sock, "Server: You are not allowed to shutdown the server!\n");
- $data = "";
- continue;
- }
-
- // Close all connections a leave here
- foreach ($clients as $client) {
- // Send message to client
- if ($client !== $mainSocket && $client != $read_sock) {
- socket_write($client, "Server: Shutting down! Thank you for joining us.\n");
- }
-
- // Quit him
- socket_shutdown($client, 2);
- socket_close($client);
- } // end foreach
-
- // Leave the loop
- $data = "";
- $clients = array();
- continue;
- }
-
- // trim off the trailing/beginning white spaces
- $data = trim($data);
-
- // Test for HTML codes
- $tags = strip_tags($data);
-
- // check if there is any data after trimming off the spaces
- if (!empty($data) && $tags == $data && count($clients) > 2) {
- // Send confirmation to "chatter"
- socket_write($read_sock, "\nServer: Message accepted.\n");
-
- // send this to all the clients in the $clients array (except the first one, which is a listening socket)
- foreach ($clients as $send_sock) {
-
- // if its the listening sock or the client that we got the message from, go to the next one in the list
- if ($send_sock == $mainSocket || $send_sock == $read_sock)
- continue;
-
- // write the message to the client -- add a newline character to the end of the message
- socket_write($send_sock, "{$ip}:{$data}\n");
-
- } // end of broadcast foreach
- } elseif ($tags != $data) {
- // HTML codes are not allowed
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has entered HTML code!");
- socket_write($read_sock, "Server: HTML is forbidden!\n");
- } elseif ((count($clients) == 2) && ($read_sock != $mainSocket)) {
- // No one else will hear the "chatter"
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} speaks with himself.");
- socket_write($read_sock, "Server: No one will hear you!\n");
- }
- } // end of reading foreach
-}
-
-// close the listening socket
-socket_close($mainSocket);
-
-?>
-<?php
-/**
- * A TCP ??? listener
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Listener extends BaseListener implements Listenable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $nodeInstance A NodeHelper instance
- * @return $listenerInstance An instance a prepared listener class
- */
- public final static function create???Listener (NodeHelper $nodeInstance) {
- // Get new instance
- $listenerInstance = new ???Listener();
-
- // Set the application instance
- $listenerInstance->setNodeInstance($nodeInstance);
-
- // Return the prepared instance
- return $listenerInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- * @todo 0% done
- */
- public function initListener() {
- $this->partialStub('Need to implement this method.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- * @todo 0% done
- */
- public function doListen() {
- $this->partialStub('Need to implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A TCP raw data handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
- /**
- * Last socket error (default: Success)
- */
- private $lastSocketError = 0;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- 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
- */
- public static final function createTcpRawDataHandler () {
- // Get new instance
- $handlerInstance = new TcpRawDataHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the TcpListener class
- *
- * @param $resource A valid socket resource array
- * @return void
- */
- public function processRawDataFromResource (array $socketArray) {
- // Check the resource
- if ((!isset($socketArray[BasePool::SOCKET_ARRAY_RESOURCE])) || (!is_resource($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]))) {
- // Throw an exception
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
- } // END - if
-
- // Reset error code to unhandled
- $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Handling TCP package from resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
-
- /*
- * Read the raw data from socket. If you change PHP_BINARY_READ to
- * PHP_NORMAL_READ, this line will endless block. This script does only
- * provide simultanous threads, not real.
- */
- $rawData = socket_read($socketArray[BasePool::SOCKET_ARRAY_RESOURCE], $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
-
- // Get socket error code back
- $this->lastSocketError = socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]);
-
- // Debug output of read data length
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',MD5=' . md5($rawData) . ',resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',error=' . socket_strerror($this->lastSocketError));
- //* NOISY-DEBUG: */ if ($rawData !== FALSE) self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: rawData=' . $rawData);
-
- // Is it valid?
- if ($this->lastSocketError == 11) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE]);
-
- /*
- * Error code 11 (Resource temporary unavailable) can be safely
- * ignored on non-blocking sockets. The socket is currently not
- * sending any data.
- */
- socket_clear_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]);
-
- // Skip any further processing
- return;
- } elseif (($rawData === FALSE) || ($this->lastSocketError > 0)) {
- // Network error or connection lost
- $this->setErrorCode($this->lastSocketError);
- } elseif (empty($rawData)) {
- // The peer did send nothing to us which is now being ignored
- return;
- } else {
- /*
- * All is fine at this point. So it is okay to add the raw data to
- * the stacker. Here it doesn't matter if the raw data is a
- * well-formed BASE64-encoded message with start and markers. This
- * will be checked later on.
- */
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Adding ' . strlen($rawData) . ' bytes to stacker ...');
- $this->addRawDataToStacker($rawData);
- }
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A UDP raw data handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UdpRawDataHandler extends BaseRawDataHandler implements Networkable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('udp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a Networkable class
- */
- public static final function createUdpRawDataHandler () {
- // Get new instance
- $handlerInstance = new UdpRawDataHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Processes raw data from given resource. This is mostly useful for UDP
- * package handling and is implemented in the UdpListener class
- *
- * @param $socketArray A valid socket resource array
- * @return void
- * @throws InvalidResourceException If the given resource is invalid
- * @todo 0%
- */
- public function processRawDataFromResource (array $socketArray) {
- // Check the resource
- if ((!isset($socketArray[BasePool::SOCKET_ARRAY_RESOURCE])) || (!is_resource($socketArray[BasePool::SOCKET_ARRAY_RESOURCE]))) {
- // Throw an exception
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
- } // END - if
-
- // Implement processing here
- $this->partialStub('Please implement this method. resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRRAY_CONN_TYPE]);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? protocol handler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???ProtocolHandler extends BaseProtocolHandler implements HandleableProtocol, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('|||_protocol');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function create???ProtocolHandler () {
- // Get new instance
- $handlerInstance = new ???ProtocolHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general handler for protocols such as TCP, UDP and others.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseProtocolHandler extends BaseHandler {
- /**
- * Whole UNL data array
- */
- private $universalNodeLocatorData = array();
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Setter for UNL data array to satify HandleableProtocol
- *
- * @para $unlData The UNL data array
- * @return void
- */
- protected final function setUniversalNodeLocatorData (array $unlData) {
- // Set new UNL data array
- $this->universalNodeLocatorData = $unlData;
- }
-
- /**
- * Getter for UNL data array to satify HandleableProtocol
- *
- * @return $unlData The UNL data array
- */
- public final function getUniversalNodeLocatorDataArray () {
- // Return UNL data array
- return $this->universalNodeLocatorData;
- }
-
- /**
- * Validates given UNL very basicly by given regular expression. You
- * normally don't need/want to overwrite this method as this is a very basic
- * validation only based on a regex.
- *
- * @param $unl Universal Node Locator to validate
- * @return $isValid Whether the UNL is valid
- */
- protected final function isValidUniversalNodeLocator ($unl) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ',regex=' . $regex . ' - CALLED!');
-
- // Very basic regex check
- $isValid = (preg_match($this->getRegularExpression(), $unl) === 1);
-
- // Return result
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: isValid=' . intval($isValid) . ' - EXIT!');
- return $isValid;
- }
-
- /**
- * Parses the given UNL by splitting it up in its components. The UNL ...
- *
- * protocol://address[:port]
- *
- * ... becomes:
- *
- * array(
- * 'protocol' => 'value',
- * 'address' => 'value',
- * 'extra' => 'port'
- * )
- *
- * The value for 'extra' then must be handled by parseUniversalNodeLocator()
- * of the individual protocol handler as this is protocol-specific.
- *
- * @param $unl Universal Node Locator (UNL) to "parse"
- * @return $unlData Array with all components of the UNL
- */
- protected function parseGenericUniversalNodeLocator ($unl) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ' - CALLED!');
-
- // Make sure the UNL is valid
- assert($this->isValidUniversalNodeLocator($unl));
-
- /*
- * "Parse" the UNL "generically", sadly this cannot be done by using preg_match() :-(
- * @TODO If you know why, please fix and explain it to me.
- */
- $unlParts = explode('://', $unl);
-
- // Split again the last part as: address:port
- $unlParts[1] = explode(':', $unlParts[1]);
-
- // Now there is an almost useable array which then can be copied to the "real" array.
- $unlData = array(
- UniversalNodeLocator::UNL_PART_PROTOCOL => $unlParts[0],
- UniversalNodeLocator::UNL_PART_ADDRESS => $unlParts[1][0],
- UniversalNodeLocator::UNL_PART_EXTRA => $unlParts[1][1]
- );
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
-
- // Return the generic array
- return $unlData;
- }
-
- /**
- * Gets an element from universalNodeLocatorData array
- *
- * @param $element Element in universalNodeLocatorData array
- * @return $value Found value
- */
- protected final function getUniversalNodeLocatorDataElement ($element) {
- // Is the element there?
- assert(isset($this->universalNodeLocatorData[$element]));
-
- // Return it
- return $this->universalNodeLocatorData[$element];
- }
-
- /**
- * "Getter" for currently saved UNL
- *
- * @return $unl Currently saved Universal Node Locator
- */
- public final function getCurrentUniversalNodeLocator () {
- // Construct generic UNL
- $unl = sprintf('%s://%s',
- $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PROTOCOL),
- $this->getAddressPart()
- );
-
- // Return it
- return $unl;
- }
-
- /**
- * Default implementation for returning address part, may not be suitable
- * for IPv4/IPv6 protocol handlers. So you have to overwrite (NOT CHANGE!) this method.
- *
- * @return $address Address part for the final UNL
- */
- public function getAddressPart () {
- // Return it
- return $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_ADDRESS);
- }
-
- /**
- * 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
- */
- public function isOwnAddress ($unl) {
- // Get own external UNL
- $externalUnl = HubTools::determineOwnExternalAddress();
-
- // Get internal UNL
- $internalUnl = HubTools::determineOwnInternalAddress();
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ',externalUnl=' . $externalUnl . ',internalUnl=' . $internalUnl);
- //* DIE-DEBUG: */ die(__METHOD__.':unl=' . $unl . ',this='.print_r($this, TRUE));
-
- // Is it the same?
- $ifMatches = (($unl === $externalUnl) || ($unl === $internalUnl));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: ifMatches=' . intval($ifMatches));
-
- // Return result
- return $ifMatches;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? protocol handler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???ProtocolHandler extends BaseProtocolHandler implements HandleableProtocol, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('|||_protocol');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function create???ProtocolHandler () {
- // Get new instance
- $handlerInstance = new ???ProtocolHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general handler for IPv4 protocols such as TCP, UDP and others.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseIpV4ProtocolHandler extends BaseProtocolHandler {
- // Regular expression for validating IP:port UNLs
- const UNL_REGEX = '/^([a-z]{1,}):\/\/\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})$/';
-
- /**
- * Port number
- */
- private $port = 0;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Set regex
- $this->setRegularExpression(self::UNL_REGEX);
- }
-
- /**
- * Setter for port number to satify HandleableProtocol
- *
- * @para $port The port number
- * @return void
- */
- protected final function setPort ($port) {
- // Set new port number
- $this->port = $port;
- }
-
- /**
- * Getter for port number to satify HandleableProtocol
- *
- * @return $port The port number
- */
- public final function getPort () {
- // Return port number
- return $this->port;
- }
-
- /**
- * Parses the given UNL by splitting it up in its components. The UNL ...
- *
- * protocol://address[:port]
- *
- * ... becomes:
- *
- * array(
- * 'protocol' => 'value',
- * 'address' => 'value',
- * 'port' => 123
- * )
- *
- * @param $unl Universal Node Locator (UNL) to "parse"
- * @return $unlData Array with all components of the UNL
- */
- protected function parseUniversalNodeLocator ($unl) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ' - CALLED!');
-
- // First generic parse
- $unlData = parent::parseGenericUniversalNodeLocator($unl);
-
- /*
- * Make sure the generic parts are all there. In case of a rewrite,
- * these assertitions will bail out on badly formed arrays.
- */
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_EXTRA]));
-
- // Copy 'extra' -> 'port' ...
- $unlData[UniversalNodeLocator::UNL_PART_PORT] = $unlData[UniversalNodeLocator::UNL_PART_EXTRA];
-
- // ... and drop 'extra'
- unset($unlData[UniversalNodeLocator::UNL_PART_EXTRA]);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
- return $unlData;
- }
-
- /**
- * 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
- */
- public function isValidUniversalNodeLocatorByPackageData (array $packageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Is 'recipient' there?
- assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
-
- // Is the correct handler choosen?
- assert(substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($this->getHandlerName())) != $this->getHandlerName());
-
- // Default is from generic validation
- $isValid = $this->isValidUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: PACKAGE_DATA_RECIPIENT=' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ',isValid[' . gettype($isValid) . ']=' . intval($isValid));
-
- // If this doesn't fail, continue validating the IP:port combination
- if ($isValid === TRUE) {
- // ... and validate IP:port, first "parse" the UNL
- $unlData = $this->parseUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
- /*
- * Make sure the extra field 'port' is there. This may look
- * superflious but in case of a rewrite this assert will stop at
- * badly formated arrays.
- */
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
-
- // Set whole UNL data array
- $this->setUniversalNodeLocatorData($unlData);
-
- // Set port
- $this->setPort($unlData[UniversalNodeLocator::UNL_PART_PORT]);
- } // END - if
-
- // Return result
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: isValid=' . intval($isValid) . ' - EXIT!');
- return $isValid;
- }
-
- /**
- * This implementation uses it's parent method and combines it with the
- * port part to construct a valid address:port combination.
- *
- * @return $address Address part for the final UNL
- */
- public function getAddressPart () {
- // Construct address
- $address = sprintf('%s:%s',
- parent::getAddressPart(),
- $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PORT)
- );
-
- // Return it
- return $address;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TCP protocol handler (IPv4)
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 TcpProtocolHandler extends BaseIpV4ProtocolHandler implements HandleableProtocol, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler and protocol type
- $this->setHandlerName('tcp_protocol');
- $this->setProtocolName('tcp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createTcpProtocolHandler () {
- // Get new instance
- $handlerInstance = new TcpProtocolHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? !!! helper class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- * @todo Find an interface for hub helper
- *
- * 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 !!!???Helper extends BaseHubSystemHelper implements Helpable!!! {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set recipient type
- $this->setRecipientType(NetworkPackage::NETWORK_TARGET_```);
-
- // Set package tags
- $this->setPackageTags(array('???'));
- }
-
- /**
- * Creates the helper class
- *
- * @return $helperInstance A prepared instance of this helper
- */
- public final static function create!!!???Helper () {
- // Get new instance
- $helperInstance = new !!!???Helper();
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the descriptor XML file
- *
- * @return void
- */
- public function loadDescriptorXml () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Do the helped attempt by delivering a package to ourselfs
- *
- * @param $|||Instance An instance of a !!!Helper class
- * @return void
- */
- public function sendPackage (!!!Helper $|||Instance) {
- // Sanity check: Is the ||| in the approx. state? (///)
- $|||Instance->getStateInstance()->validate!!!StateIs+++();
-
- // Compile the template, this inserts the loaded ||| data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- $packageInstance->enqueueRawDataFromTemplate($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general hub helper class. This class does not extend BaseHelper.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubSystemHelper extends BaseHubSystem implements HubHelper {
- /**
- * Recipient type
- */
- private $recipientType = 'invalid';
-
- /**
- * Package tags
- */
- private $packageTags = array();
-
- /**
- * Protected constructor
- *
- * @param $className Name of the concrete class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Setter for recipient type
- *
- * @return $recipientType Type of a recipient (the helper is made for)
- */
- protected final function setRecipientType ($recipientType) {
- $this->recipientType = $recipientType;
- }
-
- /**
- * Getter for recipient type
- *
- * @return $recipientType Type of a recipient (the helper is made for)
- */
- public final function getRecipientType () {
- return $this->recipientType;
- }
-
- /**
- * Getter for package tags in a simple array
- *
- * @return $packageTags An array with all tags for the currently handled package
- */
- public final function getPackageTags () {
- return $this->packageTags;
- }
-
- /**
- * Setter for package tags in a simple array
- *
- * @param $packageTags An array with all tags for the currently handled package
- * @return void
- */
- public final function setPackageTags (array $packageTags) {
- $this->packageTags = $packageTags;
- }
-
- /**
- * Tries to determine the used protocol for this package (this helper is helping to send out)
- *
- * @return $protocolType Type of protocol to use, usually TCP
- * @todo 0% done
- */
- public function determineProtocolType () {
- die(__METHOD__ . ':' . print_r($this, TRUE));
- // Return it
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? connection helper class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- * @todo Find an interface for hub helper
- *
- * 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 ???ConnectionHelper extends BaseConnectionHelper implements ConnectionHelper {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set protocol
- $this->setProtocolName('!!!');
- }
-
- /**
- * Creates a socket resource ("connection") for given recipient in package data
- *
- * @param $packageData Raw package data
- * @return $socketResource Socket resource
- */
- public static function createConnectionFromPackageData (array $packageData) {
- die();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general ConnectionHelper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseConnectionHelper extends BaseHubSystemHelper implements Registerable {
- // Exception codes
- const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x9100;
-
- /**
- * Connection type 'incoming'
- */
- const CONNECTION_TYPE_INCOMING = 'incoming';
-
- /**
- * Connection type 'outgoing'
- */
- const CONNECTION_TYPE_OUTGOING = 'outgoing';
-
- /**
- * Connection type 'server'
- */
- const CONNECTION_TYPE_SERVER = 'server';
-
- /**
- * Name of used protocol for this connection
- */
- private $connectionType = 'invalid';
-
- /**
- * (IP) Adress used
- */
- private $address = 0;
-
- /**
- * Sent data in bytes
- */
- private $sentData = 0;
-
- /**
- * Whether this connection is initialized
- */
- private $isInitialized = FALSE;
-
- /**
- * Whether this connection is shutted down
- */
- private $shuttedDown = FALSE;
-
- /**
- * Currently queued chunks
- */
- private $queuedChunks = array();
-
- /**
- * Current final hash
- */
- private $currentFinalHash = '';
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // 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);
-
- // Get package instance from factory
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // ... and set it here
- $this->setPackageInstance($packageInstance);
-
- // Register this connection helper
- Registry::getRegistry()->addInstance('connection', $this);
-
- // Get the fragmenter instance
- $fragmenterInstance = FragmenterFactory::createFragmenterInstance('package');
-
- // Set it here
- $this->setFragmenterInstance($fragmenterInstance);
- }
-
- /**
- * Getter for real class name, overwrites generic method and is final
- *
- * @return $class Name of this class
- */
- public final function __toString () {
- // Class name representation
- $class = self::getConnectionClassName($this->getAddress(), $this->getConnectionPort(), parent::__toString());
-
- // Return it
- return $class;
- }
-
- /**
- * Getter for connection type
- *
- * @return $connectionType Name of used protocol in this connection
- */
- public final function getConnectionType () {
- return $this->connectionType;
- }
-
- /**
- * Setter for connection type
- *
- * @param $connectionType Name of used protocol in this connection
- * @return void
- */
- protected final function setConnectionType ($connectionType) {
- $this->connectionType = $connectionType;
- }
-
- /**
- * Getter for IP address
- *
- * @return $address The IP address
- */
- public final function getAddress () {
- return $this->address;
- }
-
- /**
- * Setter for IP address
- *
- * @param $address The IP address
- * @return void
- */
- protected final function setAddress ($address) {
- $this->address = $address;
- }
-
- /**
- * Setter for isInitialized
- *
- * @param $isInitialized Name of used protocol in this connection
- * @return void
- */
- protected final function setIsInitialized ($isInitialized) {
- $this->isInitialized = $isInitialized;
- }
-
- /**
- * Getter for isInitialized (NOTE: no 'get' prefix for boolean attributes!)
- *
- * @return $isInitialized Name of used protocol in this connection
- */
- protected final function isInitialized () {
- return $this->isInitialized;
- }
-
- /**
- * 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
- */
- public static function getConnectionClassName ($address, $port, $className) {
- // Construct it
- $class = $address . ':' . $port . ':' . $className;
-
- // ... and return it
- return $class;
- }
-
- /**
- * Initializes the peer's state which sets it to 'init'
- *
- * @return void
- */
- private function initState() {
- // Get the state factory and create the initial state.
- PeerStateFactory::createPeerStateInstanceByName('init', $this);
- }
-
- /**
- * "Getter" for raw data from a package array. A fragmenter is used which
- * will returns us only so many raw data which fits into the back buffer.
- * The rest is being held in a back-buffer and waits there for the next
- * cycle and while be then sent.
- *
- * This method does 2 simple steps:
- * 1) Request a chunk from set fragmenter instance
- * 2) Finally return the chunk (array) to the caller
- *
- * @param $packageData Raw package data array
- * @return $chunkData Raw data chunk
- */
- private function getRawDataFromPackageArray (array $packageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: currentFinalHash=' . $this->currentFinalHash);
-
- // Make sure the final hash is set
- assert((is_string($this->currentFinalHash)) && (!empty($this->currentFinalHash)));
-
- // Get the next raw data chunk from the fragmenter
- $rawDataChunk = $this->getFragmenterInstance()->getNextRawDataChunk($this->currentFinalHash);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: rawDataChunk=' . print_r($rawDataChunk, TRUE));
-
- // Get chunk hashes and chunk data
- $chunkHashes = array_keys($rawDataChunk);
- $chunkData = array_values($rawDataChunk);
-
- // Is the required data there?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: chunkHashes[]=' . count($chunkHashes) . ',chunkData[]=' . count($chunkData));
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('chunkData='.print_r($chunkData, TRUE));
- if ((isset($chunkHashes[0])) && (isset($chunkData[0]))) {
- // Remember this chunk as queued
- $this->queuedChunks[$chunkHashes[0]] = $chunkData[0];
-
- // Return the raw data
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Returning ' . strlen($chunkData[0]) . ' bytes from ' . __METHOD__ . ' ...');
- return $chunkData[0];
- } else {
- // Return zero string
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Returning zero bytes from ' . __METHOD__ . '!');
- return '';
- }
- }
-
- /**
- * "Accept" a visitor by simply calling it back
- *
- * @param $visitorInstance A Visitor instance
- * @return void
- */
- protected final function accept (Visitor $visitorInstance) {
- // Just call the visitor
- $visitorInstance->visitConnectionHelper($this);
- }
-
- /**
- * Sends raw package data to the recipient
- *
- * @param $packageData Raw package data
- * @return void
- * @throws InvalidSocketException If we got a problem with this socket
- */
- public function sendRawPackageData (array $packageData) {
- // The helper's state must be 'connected'
- $this->getStateInstance()->validatePeerStateConnected();
-
- // 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);
-
- // Set final hash
- $this->currentFinalHash = $finalHash;
- } // END - if
-
- // Reset serial number
- $this->getFragmenterInstance()->resetSerialNumber($this->currentFinalHash);
-
- // Init variables
- $rawData = '';
- $dataStream = ' ';
-
- // Fill sending buffer with data
- while (strlen($dataStream) > 0) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE));
-
- // Convert the package data array to a raw data stream
- $dataStream = $this->getRawDataFromPackageArray($packageData);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Adding ' . strlen($dataStream) . ' bytes to the sending buffer ...');
- $rawData .= $dataStream;
- } // END - while
-
- // Nothing to sent is bad news, so assert on it
- assert(strlen($rawData) > 0);
-
- // Calculate buffer size
- $bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocolName() . '_buffer_length');
-
- // Encode the raw data with our output-stream
- $encodedData = $this->getOutputStreamInstance()->streamData($rawData);
-
- // Debug message
- //* 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
- $diff = $encodedDataArray[NetworkPackage::RAW_BUFFER_SIZE_INDEX] - strlen($encodedDataArray[NetworkPackage::RAW_ENCODED_DATA_INDEX]);
-
- // Push raw data to the package's outgoing stack
- $this->getPackageInstance()->getStackInstance()->pushNamed(NetworkPackage::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
- }
-
- /**
- * Getter for shuttedDown
- *
- * @return $shuttedDown Whether this connection is shutted down
- */
- public final function isShuttedDown () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $this->__toString() . ',shuttedDown=' . intval($this->shuttedDown));
- return $this->shuttedDown;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? connection helper class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- * @todo Find an interface for hub helper
- *
- * 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 BaseIpV4ConnectionHelper extends BaseConnectionHelper {
- /**
- * Port number used
- */
- private $connectionPort = 0;
-
- /**
- * Protected constructor
- *
- * @param $className Name of implementing class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Getter for port number to satify HandleableProtocol
- *
- * @return $connectionPort The port number
- */
- public final function getConnectionPort () {
- return $this->connectionPort;
- }
-
- /**
- * Setter for port number to satify HandleableProtocol
- *
- * @param $connectionPort The port number
- * @return void
- */
- protected final function setConnectionPort ($connectionPort) {
- $this->connectionPort = $connectionPort;
- }
-
- /**
- * Initializes the current connection
- *
- * @return void
- * @throws SocketOptionException If setting any socket option fails
- */
- protected function initConnection () {
- // Get socket resource
- $socketResource = $this->getSocketResource();
-
- // Set the option to reuse the port
- if (!socket_set_option($socketResource, SOL_SOCKET, SO_REUSEADDR, 1)) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
-
- // And throw again
- // @TODO Move this to the socket error handler
- throw new SocketOptionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
-
- /*
- * Set socket to non-blocking mode before trying to establish a link to
- * it. This is now the default behaviour for all connection helpers who
- * call initConnection(); .
- */
- if (!socket_set_nonblock($socketResource)) {
- // Handle this socket error with a faked recipientData array
- $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
-
- // And throw again
- throw new SocketOptionException(array($helperInstance, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
-
- // Last step: mark connection as initialized
- $this->setIsInitialized(TRUE);
- }
-
- /**
- * Attempts to connect to a peer by given IP number and port from a valid
- * unlData array with currently configured timeout.
- *
- * @param $unlData Valid UNL data array
- * @return $isConnected Whether the connection went fine
- * @see Please see http://de.php.net/manual/en/function.socket-connect.php#84465 for original code
- * @todo Rewrite the while() loop to a iterator to not let the software stay very long here
- */
- protected function connectToPeerByUnlData (array $unlData) {
- // Only call this if the connection is initialized by initConnection()
- assert($this->isInitialized());
-
- // Is unlData complete?
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
-
- // Get current time
- $time = time();
-
- // "Cache" socket resource and timeout config
- $socketResource = $this->getSocketResource();
- $timeout = $this->getConfigInstance()->getConfigEntry('socket_timeout_seconds');
-
- // Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Trying to connect to ' . $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] . ':' . $unlData[UniversalNodeLocator::UNL_PART_PORT] . ' with socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' ...');
-
- // Try to connect until it is connected
- while ($isConnected = !@socket_connect($socketResource, $unlData[UniversalNodeLocator::UNL_PART_ADDRESS], $unlData[UniversalNodeLocator::UNL_PART_PORT])) {
- // Get last socket error
- $socketError = socket_last_error($socketResource);
-
- // Skip any errors which may happen on non-blocking connections
- if (($socketError == SOCKET_EINPROGRESS) || ($socketError == SOCKET_EALREADY)) {
- // Now, is that attempt within parameters?
- if ((time() - $time) >= $timeout) {
- // Didn't work within timeout
- $isConnected = FALSE;
- break;
- } // END - if
-
- // Sleep about one second
- $this->idle(1000);
- } elseif ($socketError != 0) {
- // Stop on everything else pronto
- $isConnected = FALSE;
- break;
- }
- } // END - while
-
- // Is the peer connected?
- if ($isConnected === TRUE) {
- // Connection is fully established here, so change the state.
- PeerStateFactory::createPeerStateInstanceByName('connected', $this);
- } else {
- /*
- * There was a problem connecting to the peer (this state is a meta
- * state until the error handler has found the real cause).
- */
- PeerStateFactory::createPeerStateInstanceByName('problem', $this);
- }
-
- // Return status
- return $isConnected;
- }
-
- /**
- * Marks this connection as shutted down
- *
- * @return void
- */
- protected final function markConnectionShuttedDown () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $this->__toString() . ' has been marked as shutted down');
- $this->shuttedDown = TRUE;
-
- // And remove the (now invalid) socket
- $this->setSocketResource(FALSE);
- }
-
- // ************************************************************************
- // Socket error handler call-back methods
- // ************************************************************************
-
- /**
- * Handles socket error 'connection timed out', but does not clear it for
- * later debugging purposes.
- *
- * @param $socketResource A valid socket resource
- * @param $unlData A valid UNL data array
- * @return void
- * @throws SocketConnectionException The connection attempts fails with a time-out
- */
- protected function socketErrorConnectionTimedOutHandler ($socketResource, array $unlData) {
- // Get socket error code for verification
- $socketError = socket_last_error($socketResource);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($socketResource);
-
- // Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- }
-
- /**
- * Handles socket error 'resource temporary unavailable', but does not
- * clear it for later debugging purposes.
- *
- * @param $socketResource A valid socket resource
- * @param $unlData A valid UNL data array
- * @return void
- * @throws SocketConnectionException The connection attempts fails with a time-out
- */
- protected function socketErrorResourceUnavailableHandler ($socketResource, array $unlData) {
- // Get socket error code for verification
- $socketError = socket_last_error($socketResource);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($socketResource);
-
- // Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- }
-
- /**
- * Handles socket error 'connection refused', but does not clear it for
- * later debugging purposes.
- *
- * @param $socketResource A valid socket resource
- * @param $unlData A valid UNL data array
- * @return void
- * @throws SocketConnectionException The connection attempts fails with a time-out
- */
- protected function socketErrorConnectionRefusedHandler ($socketResource, array $unlData) {
- // Get socket error code for verification
- $socketError = socket_last_error($socketResource);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($socketResource);
-
- // Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- }
-
- /**
- * Handles socket error 'no route to host', but does not clear it for later
- * debugging purposes.
- *
- * @param $socketResource A valid socket resource
- * @param $unlData A valid UNL data array
- * @return void
- * @throws SocketConnectionException The connection attempts fails with a time-out
- */
- protected function socketErrorNoRouteToHostHandler ($socketResource, array $unlData) {
- // Get socket error code for verification
- $socketError = socket_last_error($socketResource);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($socketResource);
-
- // Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- }
-
- /**
- * Handles socket error 'operation already in progress' which happens in
- * method connectToPeerByUnlData() on timed out connection
- * attempts.
- *
- * @param $socketResource A valid socket resource
- * @param $unlData A valid UNL data array
- * @return void
- * @throws SocketConnectionException The connection attempts fails with a time-out
- */
- protected function socketErrorOperationAlreadyProgressHandler ($socketResource, array $unlData) {
- // Get socket error code for verification
- $socketError = socket_last_error($socketResource);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Half-shutdown this socket (see there for difference to shutdownSocket())
- $this->halfShutdownSocket($socketResource);
-
- // Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- }
-
- /**
- * Handles socket error 'connection reset by peer', but does not clear it for
- * later debugging purposes.
- *
- * @param $socketResource A valid socket resource
- * @param $unlData A valid UNL data array
- * @return void
- * @throws SocketConnectionException The connection attempts fails with a time-out
- */
- protected function socketErrorConnectionResetByPeerHandler ($socketResource, array $unlData) {
- // Get socket error code for verification
- $socketError = socket_last_error($socketResource);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($socketResource);
-
- // Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- }
-
- /**
- * Handles socket "error" 'operation now in progress' which can be safely
- * passed on with non-blocking connections.
- *
- * @param $socketResource A valid socket resource
- * @param $unlData A valid UNL data array
- * @return void
- */
- protected function socketErrorOperationInProgressHandler ($socketResource, array $unlData) {
- self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Operation is now in progress, this is usual for non-blocking connections and is no bug.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TCP connection helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 TcpConnectionHelper extends BaseIpV4ConnectionHelper implements ConnectionHelper {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set protocol
- $this->setProtocolName('tcp');
- }
-
- /**
- * Creates a half-connected socket resource ("connection") for given
- * recipient in package data. After you called this method you still need to
- * connect to the other node.
- *
- * @param $packageData Raw package data
- * @return $socketResource Socket resource
- * @throws SocketCreationException If the socket could not be created
- * @throws SocketOptionException If a socket option could not be set
- * @throws SocketConnectionException If a connection could not be opened
- * @todo $errorCode/-Message are now in handleSocketError()'s call-back methods
- */
- public static function createConnectionFromPackageData (array $packageData) {
- // Create an instance
- $helperInstance = new TcpConnectionHelper();
-
- // Create a socket instance
- $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
-
- // Is the socket resource valid?
- if (!is_resource($socketResource)) {
- /*
- * Something bad happened, calling handleSocketError() is not
- * possible here because that method would throw an
- * InvalidSocketException back.
- */
- throw new SocketCreationException(array($helperInstance, gettype($socketResource)), BaseListener::EXCEPTION_SOCKET_CREATION_FAILED);
- } // END - if
-
- // Get socket error code for verification
- $socketError = socket_last_error($socketResource);
-
- // Check if there was an error else
- if ($socketError > 0) {
- // Handle this socket error with a faked recipientData array
- $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
-
- // Then throw again
- 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);
-
- // Init connection
- $helperInstance->initConnection();
-
- // @TODO The whole resolving part should be moved out and made more configurable
- // Init recipient data
- $unlData = array();
-
- // Try to solve the recipient
- try {
- // Get protocol handler back from package data
- $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
-
- // Get UNL data
- $unlData = $handlerInstance->getUniversalNodeLocatorDataArray();
-
- // Make sure it is a valid Universal Node Locator array (3 elements)
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
-
- // Set handler instance
- $helperInstance->setHandlerInstance($handlerInstance);
- } catch (NoValidHostnameException $e) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Failed to resolve ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ':' . $e->getMessage());
-
- // Is the recipient equal as configured IP
- if (substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_address'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_address')) {
- // This may connect to shipsimu.org and requests 'ip.php' which will return our external IP address
- $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] = HubTools::determineExternalAddress();
-
- // Do we have ip:port match?
- // @TODO Rewrite this test for UNLs
- if (strpos($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], ':') === FALSE) {
- // No ip:port!
- $helperInstance->debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' does not contain ":". Please fix this.');
- } // END - if
-
- // "explode" the ip:port, so index 1 will be the port number
- // @TODO Rewrite this test for UNLs
- $recipientArray = explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
- // Add the port
- $unlData[UniversalNodeLocator::UNL_PART_PORT] = $recipientArray[UniversalNodeLocator::UNL_PART_PORT];
- } else {
- // It doesn't match, we need to take care of this later
- $helperInstance->debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . '!=' . $helperInstance->getConfigInstance()->getConfigEntry('external_address'));
- }
- }
-
- // Set address and maybe port
- $helperInstance->setAddress($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]);
- $helperInstance->setConnectionPort($unlData[UniversalNodeLocator::UNL_PART_PORT]);
-
- // Now connect to it
- if (!$helperInstance->connectToPeerByUnlData($unlData)) {
- // Handle socket error
- $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, $unlData);
- } // END - if
-
- // Okay, that should be it. Return it...
- return $socketResource;
- }
-
- /**
- * Do the shutdown sequence for this connection helper
- *
- * @return void
- * @throws SocketShutdownException If the current socket could not be shut down
- * @todo We may want to implement a filter for ease notification of other objects like our pool
- */
- public function doShutdown () {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down socket resource ' . $this->getSocketResource());
-
- // Clear any previous errors
- socket_clear_error($this->getSocketResource());
-
- // Call the shutdown function on the currently set socket
- if (!socket_shutdown($this->getSocketResource())) {
- // Could not shutdown socket, this is fine if e.g. the other side is not connected, so analyse it
- if (socket_last_error($this->getSocketResource()) != 107) {
- // Something bad happened while we shutdown a socket
- throw new SocketShutdownException($this, BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
- } // END - if
-
- // Try to make blocking IO for socket_close()
- socket_set_block($this->getSocketResource());
-
- // Drop all data (don't sent any on socket closure)
- socket_set_option($this->getSocketResource(), SOL_SOCKET, SO_LINGER, array('l_onoff' => 1, 'l_linger' => 0));
-
- // Finally close socket to free some resources
- socket_close($this->getSocketResource());
-
- // Mark this connection as shutted down
- $this->markConnectionShuttedDown();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A UDP connection helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 UdpConnectionHelper extends BaseIpV4ConnectionHelper implements ConnectionHelper {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set protocol
- $this->setProtocolName('udp');
- }
-
- /**
- * Creates a half-connected socket resource ("connection") for given
- * recipient in package data. After you called this method you still need to
- * connect to the other node.
- *
- * @param $packageData Raw package data
- * @return $socketResource Socket resource
- */
- public static function createConnectionFromPackageData (array $packageData) {
- $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: Unfinished method, packageData[]=' . count($packageData));
- }
-
- /**
- * Do the shutdown sequence for this connection helper
- *
- * @return void
- * @throws SocketShutdownException If the current socket could not be shut down
- * @todo Implement a filter for ease notification of other objects like the pool
- */
- public function doShutdown () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Bootstrap Dht helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 DhtBootstrapHelper extends BaseHubSystemHelper implements HelpableDht {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set recipient type
- $this->setRecipientType(NetworkPackage::NETWORK_TARGET_DHT);
-
- // Set package tags
- $this->setPackageTags(array('dht_bootstrap'));
- }
-
- /**
- * Creates the helper class
- *
- * @return $helperInstance A prepared instance of this helper
- */
- public final static function createDhtBootstrapHelper () {
- // Get new instance
- $helperInstance = new DhtBootstrapHelper();
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the announcement descriptor for parsing
- *
- * @param $dhtInstance An instance of a Distributable class
- * @return void
- */
- public function loadDescriptorXml (Distributable $dhtInstance) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Starting with DHT boostrap ...');
-
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('dht_bootstrap_template_class');
-
- // Set it for later use
- $this->setTemplateInstance($templateInstance);
-
- // Read the XML descriptor
- $templateInstance->loadXmlTemplate();
-
- // Render the XML content
- $templateInstance->renderXmlContent();
- }
-
- /**
- * Do the helped attempt by delivering a package to ourselfs
- *
- * @param $dhtInstance An instance of a Distributable class
- * @return void
- */
- public function sendPackage (Distributable $dhtInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- /*
- * Sanity check: Is the DHT in the approx. state? 'init' for bootstrap
- * nodes and 'virgin' for all others.
- */
- $dhtInstance->getStateInstance()->validateDhtStateIsVirginOrInit();
-
- // Compile the template, this inserts the loaded dht data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- //* DEBUG: */ die(__METHOD__ . ':dhtInstance=' . print_r($dhtInstance, TRUE));
- $packageInstance->enqueueRawDataFromTemplate($this);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A PublishingEntry Dht helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 DhtPublishEntryHelper extends BaseHubSystemHelper implements HelpableDht {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set recipient type
- $this->setRecipientType(NetworkPackage::NETWORK_TARGET_DHT);
-
- // Set package tags
- $this->setPackageTags(array('dht_publish_entry'));
- }
-
- /**
- * Creates the helper class
- *
- * @return $helperInstance A prepared instance of this helper
- */
- public final static function createDhtPublishEntryHelper () {
- // Get new instance
- $helperInstance = new DhtPublishEntryHelper();
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the announcement descriptor for parsing
- *
- * @param $dhtInstance An instance of a Distributable class
- * @return void
- */
- public function loadDescriptorXml (Distributable $dhtInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Starting with publishing an entry ...');
-
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('dht_publish_entry_template_class');
-
- // Set stacker
-
- // Set it for later use
- $this->setTemplateInstance($templateInstance);
-
- // Read the XML descriptor
- $templateInstance->loadXmlTemplate();
-
- // Render the XML content
- $templateInstance->renderXmlContent();
- }
-
- /**
- * Do the helped attempt by delivering a package to ourselfs
- *
- * @param $dhtInstance An instance of a Distributable class
- * @return void
- */
- public function sendPackage (Distributable $dhtInstance) {
- // Compile the template, this inserts the loaded dht data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- $packageInstance->enqueueRawDataFromTemplate($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? message helper
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???MessageHelper extends BaseMessageHelper implements MessageHelper {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $messageInstance An instance of a UnitHelper class
- */
- public final static function create???MessageHelper () {
- // Get new instance
- $messageInstance = new ???MessageHelper();
-
- // Return the prepared instance
- return $messageInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general Message class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseMessageHelper extends BaseFrameworkSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A CryptoRandom message helper
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CryptoRandomUnitMessageHelper extends BaseMessageHelper implements MessageHelper {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $sourceType Type of the source
- * @return $messageInstance An instance of a UnitHelper class
- */
- public final static function createCryptoRandomUnitMessageHelper ($sourceType) {
- // Get new instance
- $messageInstance = new CryptoRandomUnitMessageHelper();
-
- // Generate a source instance
- $sourceInstance = UnitSourceFactory::createUnitSourceInstance($sourceType);
-
- // Set the source instance
- $messageInstance->setSourceInstance($sourceInstance);
-
- // Return the prepared instance
- return $messageInstance;
- }
-
- /**
- * Generates an encrypted random message
- *
- * @return $encryptedMessage The encrypted random message
- */
- public function generateRandomMessage () {
- // Get the message from our source
- $encryptedMessage = $this->getSourceInstance()->generateMessageFromSource();
-
- // Return it
- return $encryptedMessage;
- }
-
- /**
- * "Getter" for an iterator for keys
- *
- * @return $iteratorInstance An instance of a Iterator class
- */
- public function getKeyIterator () {
- // Create the iterator instance
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName('test_unit_producer_key_iterator_class');
-
- // And return it
- return $iteratorInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A helper class for announcing this node to other nodes
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 NodeAnnouncementHelper extends BaseNodeHelper implements HelpableNode {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set recipient type
- $this->setRecipientType(NetworkPackage::NETWORK_TARGET_UPPER);
-
- // Set package tags
- $this->setPackageTags(array('announcement'));
- }
-
- /**
- * Creates the helper class
- *
- * @return $helperInstance A prepared instance of this helper
- */
- public static final function createNodeAnnouncementHelper () {
- // Get new instance
- $helperInstance = new NodeAnnouncementHelper();
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the announcement descriptor for parsing
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function loadDescriptorXml (NodeHelper $nodeInstance) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Starting with announcement to upper hubs...');
-
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_template_class');
-
- // Set it for later use
- $this->setTemplateInstance($templateInstance);
-
- // Read the XML descriptor
- $templateInstance->loadXmlTemplate();
-
- // Render the XML content
- $templateInstance->renderXmlContent();
- }
-
- /**
- * Publishes the node's descriptor XML to all found upper nodes when the
- * node has not yet published it's descriptor to a bootstrap node. This is
- * done by getting the raw XML content and inserting all variables into
- * the code. After this wents fine, the rendered content got "packaged"
- * for network delivery.
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function sendPackage (NodeHelper $nodeInstance) {
- // Sanity check: Is the node in the approx. state? (active)
- $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
-
- // Compile the template, this inserts the loaded node data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- $packageInstance->enqueueRawDataFromTemplate($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A AnnouncementMessageAnswer node helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init package tags
- $this->setPackageTags(array('announcement_answer'));
- }
-
- /**
- * Creates the helper class
- *
- * @param $messageData An array with all message data
- * @return $helperInstance A prepared instance of this helper
- */
- public final static function createNodeAnnouncementMessageAnswerHelper (array $messageData) {
- // Get new instance
- $helperInstance = new NodeAnnouncementMessageAnswerHelper();
-
- // Set session id of other peer as recipient
- $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
-
- // Set message data
- $helperInstance->setMessageData($messageData);
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the descriptor XML file
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function loadDescriptorXml (NodeHelper $nodeInstance) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting to answer an announcement...');
-
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_answer_template_class');
-
- // Set it for later use
- $this->setTemplateInstance($templateInstance);
-
- // Read the XML descriptor
- $templateInstance->loadXmlTemplate();
-
- // Render the XML content
- $templateInstance->renderXmlContent();
- }
-
- /**
- * Send out announcement answer package
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function sendPackage (NodeHelper $nodeInstance) {
- // Sanity check: Is the node in the approx. state? (active/reachable)
- $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
-
- // Compile the template, this inserts the loaded node data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- $packageInstance->enqueueRawDataFromTemplate($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general hub message answer helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubAnswerHelper extends BaseNodeHelper {
- /**
- * Message data array
- */
- private $messageData = array();
-
- /**
- * Protected constructor
- *
- * @param $className Name of the concrete class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Setter for message data
- *
- * @return $messageData An array with message data
- */
- protected final function setMessageData (array $messageData) {
- $this->messageData = $messageData;
- }
-
- /**
- * Getter for message data
- *
- * @return $messageData An array with message data
- */
- public final function getMessageData () {
- return $this->messageData;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A DhtBootstrapMessageAnswer node helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 NodeDhtBootstrapMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init package tags
- $this->setPackageTags(array('dht_bootstrap_answer'));
- }
-
- /**
- * Creates the helper class
- *
- * @param $messageData An array with all message data
- * @return $helperInstance A prepared instance of this helper
- */
- public final static function createNodeDhtBootstrapMessageAnswerHelper (array $messageData) {
- // Get new instance
- $helperInstance = new NodeDhtBootstrapMessageAnswerHelper();
-
- // Set session id of other peer as recipient
- $helperInstance->setRecipientType($messageData[XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID]);
-
- // Set message data
- $helperInstance->setMessageData($messageData);
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the descriptor XML file
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function loadDescriptorXml (NodeHelper $nodeInstance) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting to answer a DHT bootstrap request...');
-
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_dht_bootstrap_answer_template_class');
-
- // Set it for later use
- $this->setTemplateInstance($templateInstance);
-
- // Read the XML descriptor
- $templateInstance->loadXmlTemplate();
-
- // Render the XML content
- $templateInstance->renderXmlContent();
- }
-
- /**
- * Send out announcement answer package
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function sendPackage (NodeHelper $nodeInstance) {
- // Sanity check: Is the node in the approx. state? (active/reachable)
- $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
-
- // Compile the template, this inserts the loaded node data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- $packageInstance->enqueueRawDataFromTemplate($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A RequestNodeListMessageAnswer node helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 NodeRequestNodeListMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init package tags
- $this->setPackageTags(array('request_node_list_answer'));
- }
-
- /**
- * Creates the helper class
- *
- * @param $messageData An array with all message data
- * @return $helperInstance A prepared instance of this helper
- */
- public final static function createNodeRequestNodeListMessageAnswerHelper (array $messageData) {
- // Get new instance
- $helperInstance = new NodeRequestNodeListMessageAnswerHelper();
-
- // Set session id of other peer as recipient
- $helperInstance->setRecipientType($messageData[XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID]);
-
- // Set message data
- $helperInstance->setMessageData($messageData);
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the descriptor XML file
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function loadDescriptorXml (NodeHelper $nodeInstance) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting to answer a request: node-list...');
-
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_answer_template_class');
-
- // Set it for later use
- $this->setTemplateInstance($templateInstance);
-
- // Read the XML descriptor
- $templateInstance->loadXmlTemplate();
-
- // "Cache" entries instance for next foreach loop
- $entriesInstance = $templateInstance->getTemplateInstance();
-
- // Is must not be NULL (then it can only be a template instance)
- assert(!is_null($entriesInstance));
-
- // Render the XML content
- $templateInstance->renderXmlContent();
- }
-
- /**
- * Send out request-node-list answer package
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function sendPackage (NodeHelper $nodeInstance) {
- // Sanity check: Is the node in the approx. state? (active/reachable)
- $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
-
- // Compile the template, this inserts the loaded node data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- $packageInstance->enqueueRawDataFromTemplate($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? hub helper class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- * @todo Find an interface for hub helper
- *
- * 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 Node???Helper extends BaseNodeHelper implements HelpableNode {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set recipient type
- $this->setRecipientType(NetworkPackage::NETWORK_TARGET_!!!);
- }
-
- /**
- * Creates the helper class
- *
- * @return $helperInstance A prepared instance of this helper
- */
- public final static function createNode???Helper () {
- // Get new instance
- $helperInstance = new Node???Helper();
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the descriptor XML file
- *
- * @return void
- */
- public function loadDescriptorXml () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Do the helped attempt by delivering a package to ourselfs
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function sendPackage (NodeHelper $nodeInstance) {
- // Sanity check: Is the node in the approx. state? (active)
- $nodeInstance->getStateInstance()->validateNodeStateIsActive();
-
- // Compile the template, this inserts the loaded node data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- $packageInstance->enqueueRawDataFromTemplate($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general node helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseNodeHelper extends BaseHubSystemHelper {
- /**
- * Protected constructor
- *
- * @param $className Name of the concrete class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A SelfConnect hub helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set recipient type
- $this->setRecipientType(NetworkPackage::NETWORK_TARGET_SELF);
-
- // Set package tags
- $this->setPackageTags(array('self_connect'));
- }
-
- /**
- * Creates the helper class
- *
- * @return $helperInstance A prepared instance of this helper
- */
- public static final function createNodeSelfConnectHelper () {
- // Get new instance
- $helperInstance = new NodeSelfConnectHelper();
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the descriptor XML file
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function loadDescriptorXml (NodeHelper $nodeInstance) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting self-connect...');
-
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_self_connect_template_class');
-
- // Set it for later use
- $this->setTemplateInstance($templateInstance);
-
- // Read the XML descriptor
- $templateInstance->loadXmlTemplate();
-
- // Render the XML content
- $templateInstance->renderXmlContent();
- }
-
- /**
- * Do the self-connect attempt by delivering a package to ourselfs
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function sendPackage (NodeHelper $nodeInstance) {
- // Sanity check: Is the node in the approx. state? (active)
- $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrAnnouncing();
-
- // Compile the template, this inserts the loaded node data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- $packageInstance->enqueueRawDataFromTemplate($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? hub helper class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 NodeRequestNodeListHelper extends BaseNodeHelper implements HelpableNode {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set recipient type
- $this->setRecipientType(NetworkPackage::NETWORK_TARGET_UPPER);
-
- // Set package tags
- $this->setPackageTags(array('request_node_list'));
- }
-
- /**
- * Creates the helper class
- *
- * @return $helperInstance A prepared instance of this helper
- */
- public final static function createNodeRequestNodeListHelper () {
- // Get new instance
- $helperInstance = new NodeRequestNodeListHelper();
-
- // Return the prepared instance
- return $helperInstance;
- }
-
- /**
- * Loads the descriptor XML file
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function loadDescriptorXml (NodeHelper $nodeInstance) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Attempting to request: node-list...');
-
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_template_class');
-
- // Set it for later use
- $this->setTemplateInstance($templateInstance);
-
- // Read the XML descriptor
- $templateInstance->loadXmlTemplate();
-
- // Render the XML content
- $templateInstance->renderXmlContent();
- }
-
- /**
- * Do the helped attempt by delivering a package to ourselfs
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return void
- */
- public function sendPackage (NodeHelper $nodeInstance) {
- // Sanity check: Is the node in the approx. state? (active)
- $nodeInstance->getStateInstance()->validateNodeStateIsAnnouncementCompleted();
-
- // Compile the template, this inserts the loaded node data into the gaps.
- $this->getTemplateInstance()->compileTemplate();
-
- // Get a singleton network package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Next, feed the content in. The network package class is a pipe-through class.
- $packageInstance->enqueueRawDataFromTemplate($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? work unit helper
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Cruncher Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???WorkUnitHelper extends BaseWorkUnitHelper implements UnitHelper {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $unitInstance An instance of a UnitHelper class
- */
- public final static function create???WorkUnitHelper () {
- // Get new instance
- $unitInstance = new ???WorkUnitHelper();
-
- // Return the prepared instance
- return $unitInstance;
- }
-
- /**
- * Initializes this WU helper
- *
- * @return void
- * @todo 0% done
- */
- protected function initializeUnitHelper () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Generates a work/test/foo unit instance
- *
- * @return $unitInstance A work unit instance
- * @todo 0% done
- */
- public function generateUnit () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general WorkUnit class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
- */
-abstract class BaseWorkUnitHelper extends BaseFrameworkSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // All WU helpers needs to be initialized
- $this->initializeUnitHelper();
- }
-
- /**
- * Initializes this WU helper
- *
- * @return void
- */
- abstract protected function initializeUnitHelper ();
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A test unit helper for cruncher
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherTestUnitHelper extends BaseWorkUnitHelper implements UnitHelper {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $unitInstance An instance of a UnitHelper class
- */
- public final static function createCruncherTestUnitHelper () {
- // Get new instance
- $unitInstance = new CruncherTestUnitHelper();
-
- // Return the prepared instance
- return $unitInstance;
- }
-
- /**
- * Initializes this WU helper. This method satisfies the abstract
- * BaseWorkUnitHelper class.
- *
- * @return void
- * @todo 0% done
- */
- protected function initializeUnitHelper () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Generates a work/test/foo unit instance. This method satifies the
- * UnitHelper interface.
- *
- * @return $unitInstance A work unit instance
- * @todo 0% done
- */
- public function generateNextUnitInstance () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? information class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Info extends BaseInfo implements ShareableInfo {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $infoInstance An instance of a ShareableInfo class
- */
- public final static function create???Info () {
- // Get new instance
- $infoInstance = new ???Info();
-
- // Return the prepared instance
- return $infoInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general Info class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 BaseInfo extends BaseHubSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Connection information class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $infoInstance An instance of a ShareableInfo class
- */
- public final static function createConnectionInfo () {
- // Get new instance
- $infoInstance = new ConnectionInfo();
-
- // Return the prepared instance
- return $infoInstance;
- }
-
- /**
- * Fills the information class with data from a Listenable instance
- *
- * @param $listenerInstance An instance of a Listenable class
- * @return void
- */
- public function fillWithListenerInformation (Listenable $listenerInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $listenerInstance->getProtocolName() . ',listenerInstance=' . $listenerInstance->__toString() . ' - CALLED!');
-
- // Fill the generic array with several data from the listener:
- $this->setProtocolName($listenerInstance->getProtocolName());
- $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $listenerInstance->getListenAddress());
- $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT , $listenerInstance->getListenPort());
-
- // Set listener here
- $this->setListenerInstance($listenerInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Fills the information class with data from a ConnectionHelper instance
- *
- * @param $helperInstance An instance of a ConnectionHelper class
- * @return void
- */
- public function fillWithConnectionHelperInformation (ConnectionHelper $helperInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $helperInstance->getProtocolName() . ',helperInstance=' . $helperInstance->__toString() . ',socketResource=' . $helperInstance->getSocketResource() . ' - CALLED!');
-
- // Fill the generic array with several data from the listener:
- $this->setProtocolName($helperInstance->getProtocolName());
- $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $helperInstance->getAddress());
- $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT , $helperInstance->getConnectionPort());
-
- // Set helper here
- $this->setHelperInstance($helperInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Getter for address
- *
- * @return $address Address from shared information
- */
- public final function getAddress () {
- // Return it from generic array
- return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS);
- }
-
- /**
- * Getter for port
- *
- * @return $port Port from shared information
- */
- public final function getPort () {
- // Return it from generic array
- return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A HubPing iterator
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubPingIterator extends BaseIterator implements Iterator {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $iteratorInstance An instance of a Iterator class
- */
- public static final function createHubPingIterator () {
- // Get new instance
- $iteratorInstance = new HubPingIterator();
-
- // Return the prepared instance
- return $iteratorInstance;
- }
-
- /**
- * Getter for current value from group or generic
- *
- * @return $current Current value in iteration
- */
- public function current () {
- // Default is null
- $current = NULL;
-
- $this->partialStub('Please implement this method.');
-
- // Return it
- return $current;
- }
-
- /**
- * Getter for key from group or generic
- *
- * @return $key Current key in iteration
- */
- public function key () {
- // Default is null
- $key = NULL;
-
- $this->partialStub('Please implement this method.');
-
- // Return it
- return $key;
- }
-
- /**
- * Advances to the next entry
- *
- * @return void
- */
- public function next () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Rewinds to the beginning of the iteration
- *
- * @return void
- */
- public function rewind () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Checks whether the current entry is valid (not at the end of the list)
- *
- * @return void
- */
- public function valid () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A NetworkListen iterator
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This current implementation is not recommended, use a
- * @todo latency-based iteration or similar approaches
- *
- * 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 NetworkListenIterator extends BaseIterator implements Iterator {
- /**
- * Key for the global list index
- */
- private $indexKey = 0;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listInstance A list of a Listable
- * @return $iteratorInstance An instance a Iterator class
- */
- public static final function createNetworkListenIterator (Listable $listInstance) {
- // Get new instance
- $iteratorInstance = new NetworkListenIterator();
-
- // Set the list
- $iteratorInstance->setListInstance($listInstance);
-
- // Return the prepared instance
- return $iteratorInstance;
- }
-
- /**
- * Getter for current value from group or generic
- *
- * @return $current Current value in iteration
- * @throws IndexOutOfBoundsException If $indexKey is out of bounds
- */
- public function current () {
- // Default is null
- $current = NULL;
-
- // Is the entry valid?
- if (!$this->valid()) {
- // Throw an exception here
- throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
- } // END - if
-
- // Now get the entry
- $current = $this->getListInstance()->getEntry($this->key());
-
- // Return it
- return $current;
- }
-
- /**
- * Getter for key from group or generic
- *
- * @return $indexKey Current key in iteration
- */
- public function key () {
- return $this->indexKey;
- }
-
- /**
- * Advances to the next entry
- *
- * @return void
- */
- public function next () {
- $this->indexKey++;
- }
-
- /**
- * Rewinds to the beginning of the iteration
- *
- * @return void
- */
- public function rewind () {
- $this->indexKey = 0;
- }
-
- /**
- * Checks whether the current entry is valid (not at the end of the list)
- *
- * @return $isValid Whether the current entry is there
- */
- public function valid () {
- // Check for total active peers and if we are not at the end
- $isValid = ($this->key() < $this->getListInstance()->count());
-
- // Return result
- return $isValid;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A handler ??? iterator
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Handler???Iterator extends BaseIterator implements Iterator {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $iteratorInstance An instance a Iterator class
- */
- public final static function createHandler???Iterator () {
- // Get new instance
- $iteratorInstance = new Handler???Iterator();
-
- // Return the prepared instance
- return $iteratorInstance;
- }
-
- /**
- * Getter for current value from group or generic
- *
- * @return $current Current value in iteration
- */
- public function current () {
- // Default is null
- $current = null;
-
- $this->partialStub('Please implement this method.');
-
- // Return it
- return $current;
- }
-
- /**
- * Getter for key from group or generic
- *
- * @return $key Current key in iteration
- */
- public function key () {
- // Default is null
- $key = null;
-
- $this->partialStub('Please implement this method.');
-
- // Return it
- return $key;
- }
-
- /**
- * Advances to the next entry
- *
- * @return void
- */
- public function next () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Rewinds to the beginning of the iteration
- *
- * @return void
- */
- public function rewind () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Checks wether the current entry is valid (not at the end of the list)
- *
- * @return void
- */
- public function valid () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A HandlerPool iterator
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This current implementation is not recommended, use a
- * @todo latency-based iteration or similar approaches
- *
- * 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 HandlerPoolIterator extends BaseIterator implements Iterator {
- /**
- * Key for the global list index
- */
- private $indexKey = 0;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listInstance A list of a Listable
- * @return $iteratorInstance An instance a Iterator class
- */
- public static final function createHandlerPoolIterator (Listable $listInstance) {
- // Get new instance
- $iteratorInstance = new HandlerPoolIterator();
-
- // Set the list
- $iteratorInstance->setListInstance($listInstance);
-
- // Return the prepared instance
- return $iteratorInstance;
- }
-
- /**
- * Getter for current value from group or generic
- *
- * @return $current Current value in iteration
- * @throws IndexOutOfBoundsException If $indexKey is out of bounds
- */
- public function current () {
- // Default is null
- $current = NULL;
-
- // Is the entry valid?
- if (!$this->valid()) {
- // Throw an exception here
- throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
- } // END - if
-
- // Now get the entry
- $current = $this->getListInstance()->getEntry($this->key());
-
- // Return it
- return $current;
- }
-
- /**
- * Getter for key from group or generic
- *
- * @return $indexKey Current key in iteration
- */
- public function key () {
- return $this->indexKey;
- }
-
- /**
- * Advances to the next entry
- *
- * @return void
- */
- public function next () {
- $this->indexKey++;
- }
-
- /**
- * Rewinds to the beginning of the iteration
- *
- * @return void
- */
- public function rewind () {
- $this->indexKey = 0;
- }
-
- /**
- * Checks whether the current entry is valid (not at the end of the list)
- *
- * @return $isValid Whether the current entry is there
- */
- public function valid () {
- // Check for total active peers and if we are not at the end
- $isValid = ($this->key() < $this->getListInstance()->count());
-
- // Return result
- return $isValid;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A MonitorPool iterator
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This current implementation is not recommended, use a
- * @todo latency-based iteration or similar approaches
- *
- * 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 MonitorPoolIterator extends BaseIterator implements Iterator, Registerable {
- /**
- * Key for the global list index
- */
- private $indexKey = 0;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listInstance A list of a Listable
- * @return $iteratorInstance An instance a Iterator class
- */
- public static final function createMonitorPoolIterator (Listable $listInstance) {
- // Get new instance
- $iteratorInstance = new MonitorPoolIterator();
-
- // Set the list
- $iteratorInstance->setListInstance($listInstance);
-
- // Return the prepared instance
- return $iteratorInstance;
- }
-
- /**
- * Getter for current value from group or generic
- *
- * @return $current Current value in iteration
- * @throws IndexOutOfBoundsException If $indexKey is out of bounds
- */
- public function current () {
- // Default is null
- $current = NULL;
-
- // Is the entry valid?
- if (!$this->valid()) {
- // Throw an exception here
- throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
- } // END - if
-
- // Now get the entry
- $current = $this->getListInstance()->getEntry($this->key());
-
- // Return it
- return $current;
- }
-
- /**
- * Getter for key from group or generic
- *
- * @return $indexKey Current key in iteration
- */
- public function key () {
- return $this->indexKey;
- }
-
- /**
- * Advances to the next entry
- *
- * @return void
- */
- public function next () {
- $this->indexKey++;
- }
-
- /**
- * Rewinds to the beginning of the iteration
- *
- * @return void
- */
- public function rewind () {
- $this->indexKey = 0;
- }
-
- /**
- * Checks whether the current entry is valid (not at the end of the list)
- *
- * @return $isValid Whether the current entry is there
- */
- public function valid () {
- // Check for total active peers and if we are not at the end
- $isValid = ($this->key() < $this->getListInstance()->count());
-
- // Return result
- return $isValid;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A shutdown ??? iterator
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Shutdown???Iterator extends BaseIterator implements Iterator {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $iteratorInstance An instance a Iterator class
- */
- public final static function createShutdown???Iterator () {
- // Get new instance
- $iteratorInstance = new Shutdown???Iterator();
-
- // Return the prepared instance
- return $iteratorInstance;
- }
-
- /**
- * Getter for current value from group or generic
- *
- * @return $current Current value in iteration
- */
- public function current () {
- // Default is null
- $current = null;
-
- $this->partialStub('Please implement this method.');
-
- // Return it
- return $current;
- }
-
- /**
- * Getter for key from group or generic
- *
- * @return $key Current key in iteration
- */
- public function key () {
- // Default is null
- $key = null;
-
- $this->partialStub('Please implement this method.');
-
- // Return it
- return $key;
- }
-
- /**
- * Advances to the next entry
- *
- * @return void
- */
- public function next () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Rewinds to the beginning of the iteration
- *
- * @return void
- */
- public function rewind () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Checks wether the current entry is valid (not at the end of the list)
- *
- * @return void
- */
- public function valid () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ShutdownPool iterator
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ShutdownPoolIterator extends BaseIterator implements Iterator {
- /**
- * Key for the global list index
- */
- private $indexKey = 0;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listInstance A list of a Listable
- * @return $iteratorInstance An instance a Iterator class
- */
- public static final function createShutdownPoolIterator (Listable $listInstance) {
- // Get new instance
- $iteratorInstance = new ShutdownPoolIterator();
-
- // Set the list
- $iteratorInstance->setListInstance($listInstance);
-
- // Return the prepared instance
- return $iteratorInstance;
- }
-
- /**
- * Getter for current value from group or generic
- *
- * @return $current Current value in iteration
- * @throws IndexOutOfBoundsException If $indexKey is out of bounds
- */
- public function current () {
- // Default is null
- $current = NULL;
-
- // Is the entry valid?
- if (!$this->valid()) {
- // Throw an exception here
- throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
- } // END - if
-
- // Now get the entry
- $current = $this->getListInstance()->getEntry($this->key());
-
- // Return it
- return $current;
- }
-
- /**
- * Getter for key from group or generic
- *
- * @return $indexKey Current key in iteration
- */
- public function key () {
- return $this->indexKey;
- }
-
- /**
- * Advances to the next entry
- *
- * @return void
- */
- public function next () {
- $this->indexKey++;
- }
-
- /**
- * Rewinds to the beginning of the iteration
- *
- * @return void
- */
- public function rewind () {
- $this->indexKey = 0;
- }
-
- /**
- * Checks whether the current entry is valid (not at the end of the list)
- *
- * @return $isValid Whether the current entry is there
- */
- public function valid () {
- // Check for total active peers and if we are not at the end
- $isValid = ($this->key() < $this->getListInstance()->count());
-
- // Return result
- return $isValid;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TaskPool iterator
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This current implementation is not recommended, use a
- * @todo latency-based iteration or similar approaches
- *
- * 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 TaskPoolIterator extends BaseIterator implements Iterator, Registerable {
- /**
- * Key for the global list index
- */
- private $indexKey = 0;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listInstance A list of a Listable
- * @return $iteratorInstance An instance a Iterator class
- */
- public static final function createTaskPoolIterator (Listable $listInstance) {
- // Get new instance
- $iteratorInstance = new TaskPoolIterator();
-
- // Set the list
- $iteratorInstance->setListInstance($listInstance);
-
- // Return the prepared instance
- return $iteratorInstance;
- }
-
- /**
- * Getter for current value from group or generic
- *
- * @return $current Current value in iteration
- * @throws IndexOutOfBoundsException If $indexKey is out of bounds
- */
- public function current () {
- // Default is null
- $current = NULL;
-
- // Is the entry valid?
- if (!$this->valid()) {
- // Throw an exception here
- throw new IndexOutOfBoundsException($this->key(), self::EXCEPTION_INDEX_OUT_OF_BOUNDS);
- } // END - if
-
- // Now get the entry
- $current = $this->getListInstance()->getEntry($this->key());
-
- // Return it
- return $current;
- }
-
- /**
- * Getter for key from group or generic
- *
- * @return $indexKey Current key in iteration
- */
- public function key () {
- return $this->indexKey;
- }
-
- /**
- * Advances to the next entry
- *
- * @return void
- */
- public function next () {
- $this->indexKey++;
- }
-
- /**
- * Rewinds to the beginning of the iteration
- *
- * @return void
- */
- public function rewind () {
- $this->indexKey = 0;
- }
-
- /**
- * Checks whether the current entry is valid (not at the end of the list)
- *
- * @return $isValid Whether the current entry is there
- */
- public function valid () {
- // Check for total active peers and if we are not at the end
- $isValid = ($this->key() < $this->getListInstance()->count());
-
- // Return result
- return $isValid;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TestUnitKeyProducer iterator
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TestUnitKeyProducerIterator extends BaseIterator implements Iterator {
- /**
- * Maximum different bit combinations
- */
- private $maxBits = 0;
-
- /**
- * Key length
- */
- private $keyLength = 0;
-
- /**
- * Current iteration
- */
- private $currentIteration = 0;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Get key length
- $this->keyLength = $this->getConfigInstance()->getConfigEntry('test_unit_random_secret_key_length');
-
- // Make sure the key length isn't getting to big (32 byte = 256 bit is really, really a lot!)
- assert($this->keyLength <= (8 * 32));
-
- // Set max bits entry
- $this->maxBits = pow(2, $this->keyLength);
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('ITERATOR: maxBits=' . $this->maxBits . ',keyLength=' . $this->keyLength . ' bits');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $iteratorInstance An instance of a Iterator class
- */
- public final static function createTestUnitKeyProducerIterator () {
- // Get new instance
- $iteratorInstance = new TestUnitKeyProducerIterator();
-
- // Return the prepared instance
- return $iteratorInstance;
- }
-
- /**
- * Getter for current value
- *
- * @return $current Current value in iteration
- */
- public function current () {
- // Calculate ASCII string representation of the key number
- $current = $this->dec2asc($this->currentIteration);
-
- // Prepend more zeros
- $current = str_pad($current, ($this->keyLength / 8), chr(0), STR_PAD_LEFT);
-
- // Return it
- return $current;
- }
-
- /**
- * Getter for key from group or generic
- *
- * @return $key Current key in iteration
- * @throws UnsupportedOperationException This method should not be called
- */
- public function key () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Advances to the next entry
- *
- * @return void
- */
- public function next () {
- /*
- * This is of course a very ineffective key generation iterator because
- * it will create a lot of keys that will never decode an encrypted
- * message. If you know a better algorithm which is freely available and
- * can be implemented as an itertator please contact me.
- */
- $this->currentIteration++;
- }
-
- /**
- * Rewinds to the beginning of the iteration
- *
- * @return void
- * @throws UnsupportedOperationException This method should not be called
- */
- public function rewind () {
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Checks whether the current entry is valid (not at the end of the list)
- *
- * @return void
- */
- public function valid () {
- return ($this->currentIteration <= $this->maxBits);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A general decorator for listeners to communicate to hubs
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseListenerDecorator extends BaseDecorator implements Visitable {
- /**
- * Listener type
- */
- private $listenerType = 'invalid';
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Getter for listen address
- *
- * @return $listenAddress The address this listener should listen on
- */
- public final function getListenAddress () {
- return $this->getListenerInstance()->getListenAddress();
- }
-
- /**
- * Getter for listen port
- *
- * @return $listenPort The port this listener should listen on
- */
- public final function getListenPort () {
- return $this->getListenerInstance()->getListenPort();
- }
-
- /**
- * Getter for connection type
- *
- * @return $connectionType Connection type for this listener
- */
- public final function getConnectionType () {
- return $this->getListenerInstance()->getConnectionType();
- }
-
- /**
- * Accepts the visitor to process the visit "request"
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this decorator
- $visitorInstance->visitDecorator($this);
-
- // Visit the covered class
- $visitorInstance->visitListener($this->getListenerInstance());
- }
-
- /**
- * Getter for listener type.
- *
- * @return $listenerType The listener's type (hub/peer)
- */
- public final function getListenerType () {
- return $this->listenerType;
- }
-
- /**
- * Setter for listener type.
- *
- * @param $listenerType The listener's type (hub/peer)
- * @return void
- */
- protected final function setListenerType ($listenerType) {
- $this->listenerType = $listenerType;
- }
-
- /**
- * Getter for peer pool instance
- *
- * @return $poolInstance A peer pool instance
- */
- public final function getPoolInstance () {
- return $this->getListenerInstance()->getPoolInstance();
- }
-
- /**
- * Monitors incoming raw data from the handler and transfers it to the
- * given receiver instance.
- *
- * @return void
- */
- public function monitorIncomingRawData () {
- // Get the handler instance
- $handlerInstance = $this->getListenerInstance()->getHandlerInstance();
-
- /*
- * Does our deocorated listener (or even a decorator again) have a
- * handler assigned? Remember that a handler will hold all incoming raw
- * data and not a listener.
- */
- if (!$handlerInstance instanceof Networkable) {
- // Skip this silently for now. Later on, this will become mandatory!
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('No handler assigned to this listener decorator. this=' . $this->__toString() . ', listenerInstance=' . $this->getListenerInstance()->__toString());
- return;
- } // END - if
-
- // Does the handler have some decoded data pending?
- if (!$handlerInstance->isRawDataPending()) {
- // No data is pending so skip further code silently
- return;
- } // END - if
-
- // Get receiver (network package) instance
- $receiverInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- /*
- * We have some pending decoded data. The receiver instance is an
- * abstract network package (which can be received and sent out) so
- * handle the decoded data over. At this moment we don't need to know
- * if the decoded data origins from a TCP or UDP connection so we can
- * just pass it over to the network package receiver
- */
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-LISTENER-DECORATOR[' . __METHOD__ . ':' . __LINE__ . '] Going to handle over some raw data to receiver instance (' . $receiverInstance->__toString() . ') ...');
- $receiverInstance->addRawDataToIncomingStack($handlerInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-while (count($clients) > 0) {
- // create a copy, so $clients doesn't get modified by socket_select()
- $read = $clients;
-
- // get a list of all the clients that have data to be read from
- // if there are no clients with data, go to next iteration
- $left = @socket_select($read, $write = null, $except = null, 0, 150);
- if ($left < 1) {
- continue;
- }
-
- // check if there is a client trying to connect
- if (in_array($mainSocket, $read)) {
- // accept the client, and add him to the $clients array
- $new_sock = socket_accept($mainSocket);
- $clients[] = $new_sock;
-
- // send the client a welcome message
- socket_write($new_sock, "No noobs, but I'll make an exception. :)\n".
- "There are ".(count($clients) - 1)." client(s) connected to the server.\n");
-
- socket_getpeername($new_sock, $ip);
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:New client connected: {$ip}");
-
- // Notify all chatter
- if (count($clients) > 2) {
- foreach ($clients as $send_sock) {
- if ($send_sock != $mainSocket && $send_sock != $new_sock) {
- socket_write($send_sock, "Server: Chatter has joined from {$ip}. There are now ".(count($clients) - 1)." clients.\n");
- }
- }
- }
-
- // remove the listening socket from the clients-with-data array
- $key = array_search($mainSocket, $read);
- unset($read[$key]);
- }
-
- // loop through all the clients that have data to read from
- foreach ($read as $read_sock) {
- // Get client data
- socket_getpeername($read_sock, $ip);
-
- // read until newline or 1024 bytes
- // socket_read while show errors when the client is disconnected, so silence the error messages
- $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ);
-
- // check if the client is disconnected
- if (($data === FALSE) || (in_array(strtolower(trim($data)), $leaving))) {
-
- // remove client for $clients array
- $key = array_search($read_sock, $clients);
- unset($clients[$key]);
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client from {$ip} disconnected. Left: ".(count($clients) - 1)."");
-
- // Notify all chatter
- if (count($clients) > 1) {
- foreach ($clients as $send_sock) {
- if ($send_sock != $mainSocket) {
- socket_write($send_sock, "Server: Chatter from {$ip} has logged out. ".(count($clients) - 1)." client(s) left.\n");
- }
- }
- }
-
- // continue to the next client to read from, if any
- socket_write($read_sock, "Server: Good bye.\n");
- socket_shutdown($read_sock, 2);
- socket_close($read_sock);
- continue;
- } elseif (in_array(trim($data), $shutdown)) {
- // Is he allowed to shutdown?
- if (!in_array($ip, $masters)) {
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has tried to shutdown the server!");
- socket_write($read_sock, "Server: You are not allowed to shutdown the server!\n");
- $data = "";
- continue;
- }
-
- // Close all connections a leave here
- foreach ($clients as $client) {
- // Send message to client
- if ($client !== $mainSocket && $client != $read_sock) {
- socket_write($client, "Server: Shutting down! Thank you for joining us.\n");
- }
-
- // Quit him
- socket_shutdown($client, 2);
- socket_close($client);
- } // end foreach
-
- // Leave the loop
- $data = "";
- $clients = array();
- continue;
- }
-
- // trim off the trailing/beginning white spaces
- $data = trim($data);
-
- // Test for HTML codes
- $tags = strip_tags($data);
-
- // check if there is any data after trimming off the spaces
- if (!empty($data) && $tags == $data && count($clients) > 2) {
- // Send confirmation to "chatter"
- socket_write($read_sock, "\nServer: Message accepted.\n");
-
- // send this to all the clients in the $clients array (except the first one, which is a listening socket)
- foreach ($clients as $send_sock) {
-
- // if its the listening sock or the client that we got the message from, go to the next one in the list
- if ($send_sock == $mainSocket || $send_sock == $read_sock)
- continue;
-
- // write the message to the client -- add a newline character to the end of the message
- socket_write($send_sock, "{$ip}:{$data}\n");
-
- } // end of broadcast foreach
- } elseif ($tags != $data) {
- // HTML codes are not allowed
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has entered HTML code!");
- socket_write($read_sock, "Server: HTML is forbidden!\n");
- } elseif ((count($clients) == 2) && ($read_sock != $mainSocket)) {
- // No one else will hear the "chatter"
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} speaks with himself.");
- socket_write($read_sock, "Server: No one will hear you!\n");
- }
- } // end of reading foreach
-}
-
-// close the listening socket
-socket_close($mainSocket);
-
-?>
-<?php
-/**
- * A TCP ??? listener
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Listener extends BaseListener implements Listenable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $nodeInstance A NodeHelper instance
- * @return $listenerInstance An instance a prepared listener class
- */
- public final static function create???Listener (NodeHelper $nodeInstance) {
- // Get new instance
- $listenerInstance = new ???Listener();
-
- // Set the application instance
- $listenerInstance->setNodeInstance($nodeInstance);
-
- // Return the prepared instance
- return $listenerInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- * @todo 0% done
- */
- public function initListener() {
- $this->partialStub('Need to implement this method.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- * @todo 0% done
- */
- public function doListen() {
- $this->partialStub('Need to implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A TCP connection listener
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TcpListener extends BaseListener implements Listenable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set the protocol to TCP
- $this->setProtocolName('tcp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $nodeInstance A NodeHelper instance
- * @return $listenerInstance An instance a prepared listener class
- */
- public static final function createTcpListener (NodeHelper $nodeInstance) {
- // Get new instance
- $listenerInstance = new TcpListener();
-
- // Return the prepared instance
- return $listenerInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- * @throws InvalidSocketException Thrown if the socket could not be initialized
- */
- public function initListener () {
- // Create a streaming socket, of type TCP/IP
- $mainSocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
-
- // Is the socket resource valid?
- if (!is_resource($mainSocket)) {
- // Something bad happened
- throw new InvalidSocketException(array($this, $mainSocket), BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
-
- // Get socket error code for verification
- $socketError = socket_last_error($mainSocket);
-
- // Check if there was an error else
- if ($socketError > 0) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
- /*
- // Then throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, socket_strerror($socketError)), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
-
- // Set the option to reuse the port
- if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
- /*
- // Get socket error code for verification
- $socketError = socket_last_error($mainSocket);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($mainSocket);
-
- // And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
-
- /*
- * "Bind" the socket to the given address, on given port so this means
- * that all connections on this port are now our resposibility to
- * send/recv data, disconnect, etc..
- */
- self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
- if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
- /*
- // Get socket error code for verification
- $socketError = socket_last_error($mainSocket);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($mainSocket);
-
- // And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
-
- // Start listen for connections
- self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Listening for connections.');
- if (!socket_listen($mainSocket)) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
- /*
- // Get socket error code for verification
- $socketError = socket_last_error($mainSocket);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($mainSocket);
-
- // And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
-
- // Now, we want non-blocking mode
- self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Setting non-blocking mode.');
- if (!socket_set_nonblock($mainSocket)) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
- /*
- // Get socket error code for verification
- $socketError = socket_last_error($mainSocket);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($mainSocket);
-
- // And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
-
- // Set the main socket
- $this->registerServerSocketResource($mainSocket);
-
- // Initialize the peer pool instance
- $poolInstance = ObjectFactory::createObjectByConfiguredName('node_pool_class', array($this));
-
- // Add main socket
- $poolInstance->addPeer($mainSocket, BaseConnectionHelper::CONNECTION_TYPE_SERVER);
-
- // And add it to this listener
- $this->setPoolInstance($poolInstance);
-
- // Initialize iterator for listening on packages
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName('network_listen_iterator_class', array($poolInstance->getPoolEntriesInstance()));
-
- // Rewind it and remember it in this class
- $iteratorInstance->rewind();
- $this->setIteratorInstance($iteratorInstance);
-
- // Initialize the network package handler
- $handlerInstance = ObjectFactory::createObjectByConfiguredName('tcp_raw_data_handler_class');
-
- // Set it in this class
- $this->setHandlerInstance($handlerInstance);
-
- // Output message
- self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- * @throws InvalidSocketException If an invalid socket resource has been found
- */
- public function doListen () {
- // Get all readers
- $readers = $this->getPoolInstance()->getAllSingleSockets();
- $writers = array();
- $excepts = array();
-
- // Check if we have some peers left
- $left = socket_select(
- $readers,
- $writers,
- $excepts,
- 0,
- 150
- );
-
- // Some new peers found?
- if ($left < 1) {
- // Debug message
- //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
-
- // Nothing new found
- return;
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
-
- // Do we have changed peers?
- if (in_array($this->getSocketResource(), $readers)) {
- /*
- * Then accept it, if this socket is set to non-blocking IO and the
- * connection is NOT sending any data, socket_read() may throw
- * error 11 (Resource temporary unavailable). This really nasty
- * because if you have blocking IO socket_read() will wait and wait
- * and wait ...
- */
- $newSocket = socket_accept($this->getSocketResource());
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketResource());
-
- // Array for timeout settings
- $options = array(
- // Seconds
- 'sec' => $this->getConfigInstance()->getConfigEntry('tcp_socket_accept_wait_sec'),
- // Milliseconds
- 'usec' => $this->getConfigInstance()->getConfigEntry('tcp_socket_accept_wait_usec')
- );
-
- // Set timeout to configured seconds
- // @TODO Does this work on Windozer boxes???
- if (!socket_set_option($newSocket, SOL_SOCKET, SO_RCVTIMEO, $options)) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
- } // END - if
-
- // Output result (only for debugging!)
- /*
- $option = socket_get_option($newSocket, SOL_SOCKET, SO_RCVTIMEO);
- self::createDebugInstance(__CLASS__)->debugOutput('SO_RCVTIMEO[' . gettype($option) . ']=' . print_r($option, TRUE));
- */
-
- // Enable SO_OOBINLINE
- if (!socket_set_option($newSocket, SOL_SOCKET, SO_OOBINLINE ,1)) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
- } // END - if
-
- // Set non-blocking
- if (!socket_set_nonblock($newSocket)) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
- } // END - if
-
- // Add it to the peers
- $this->getPoolInstance()->addPeer($newSocket, BaseConnectionHelper::CONNECTION_TYPE_INCOMING);
-
- // Get peer name
- if (!socket_getpeername($newSocket, $peerName)) {
- // Handle this socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
- } // END - if
-
- // Get node instance
- $nodeInstance = Registry::getRegistry()->getInstance('node');
-
- // Create a faked package data array
- $packageData = array(
- NetworkPackage::PACKAGE_DATA_SENDER => $peerName . ':0',
- NetworkPackage::PACKAGE_DATA_RECIPIENT => $nodeInstance->getSessionId(),
- NetworkPackage::PACKAGE_DATA_STATUS => NetworkPackage::PACKAGE_STATUS_FAKED
- );
-
- // Get a connection info instance
- $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
-
- // Will the info instance with listener data
- $infoInstance->fillWithListenerInformation($this);
-
- // Get a socket registry
- $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
-
- // Register the socket with the registry and with the faked array
- $registryInstance->registerSocket($infoInstance, $newSocket, $packageData);
- } // END - if
-
- // Do we have to rewind?
- if (!$this->getIteratorInstance()->valid()) {
- // Rewind the list
- $this->getIteratorInstance()->rewind();
- } // END - if
-
- // Get the current value
- $currentSocket = $this->getIteratorInstance()->current();
-
- // Handle it here, if not main server socket
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->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())) {
- // ... or else it will raise warnings like 'Transport endpoint is not connected'
- $this->getHandlerInstance()->processRawDataFromResource($currentSocket);
- } // END - if
-
- // Advance to next entry. This should be the last line.
- $this->getIteratorInstance()->next();
- }
-
- /**
- * Checks whether the listener would accept the given package data array
- *
- * @param $packageData Raw package data
- * @return $accepts Whether this listener does accept
- * @throws UnsupportedOperationException If this method is called
- */
- public function ifListenerAcceptsPackageData (array $packageData) {
- // Please don't call this
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A decorator for the TcpListener to communicate to peers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ClientTcpListenerDecorator extends BaseListenerDecorator implements Listenable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set listener type and protocol name
- $this->setListenerType('peer');
- $this->setProtocolName('tcp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listenerInstance A Listener instance
- * @return $decoratorInstance An instance a prepared listener decorator class
- */
- public static final function createClientTcpListenerDecorator (Listenable $listenerInstance) {
- // Get new instance
- $decoratorInstance = new ClientTcpListenerDecorator();
-
- // Set the application instance
- $decoratorInstance->setListenerInstance($listenerInstance);
-
- // Return the prepared instance
- return $decoratorInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- */
- public function initListener () {
- $this->partialStub('WARNING: This method should not be called.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- */
- public function doListen () {
- // Handle generic TCP package
- $this->getListenerInstance()->doListen();
-
- // Handle peer TCP package
- $this->partialStub('Need to handle peer TCP package.');
- }
-
- /**
- * Checks whether the listener would accept the given package data array
- *
- * @param $packageData Raw package data
- * @return $accepts Whether this listener does accept
- */
- public function ifListenerAcceptsPackageData (array $packageData) {
- // Get a tags instance
- $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
-
- // So is the package accepted with this listener?
- $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
-
- // Return the result
- return $accepts;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A decorator for the TcpListener to communicate to hubs
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubTcpListenerDecorator extends BaseListenerDecorator implements Listenable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set listener type and protocol name
- $this->setListenerType('hub');
- $this->setProtocolName('tcp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listenerInstance A Listener instance
- * @return $decoratorInstance An instance a prepared listener decorator class
- */
- public static final function createHubTcpListenerDecorator (Listenable $listenerInstance) {
- // Get new instance
- $decoratorInstance = new HubTcpListenerDecorator();
-
- // Set the application instance
- $decoratorInstance->setListenerInstance($listenerInstance);
-
- // Return the prepared instance
- return $decoratorInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- */
- public function initListener () {
- $this->partialStub('WARNING: This method should not be called.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- */
- public function doListen () {
- // Handle generic TCP package
- $this->getListenerInstance()->doListen();
-
- // Handle hub TCP package
- $this->partialStub('Need to handle hub TCP package.');
- }
-
- /**
- * Checks whether the listener would accept the given package data array
- *
- * @param $packageData Raw package data
- * @return $accepts Whether this listener does accept
- */
- public function ifListenerAcceptsPackageData (array $packageData) {
- // Get a tags instance
- $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
-
- // So is the package accepted with this listener?
- $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
-
- // Return the result
- return $accepts;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An UDP ??? listener
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Udp???Listener extends BaseListener implements Listenable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $nodeInstance A NodeHelper instance
- * @return $listenerInstance An instance a prepared listener class
- */
- public final static function createUdp???Listener (NodeHelper $nodeInstance) {
- // Get new instance
- $listenerInstance = new Udp???Listener();
-
- // Set the application instance
- $listenerInstance->setNodeInstance($nodeInstance);
-
- // Return the prepared instance
- return $listenerInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- * @todo 0% done
- */
- public function initListener() {
- $this->partialStub('Need to implement this method.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- * @todo 0% done
- */
- public function doListen() {
- $this->partialStub('Need to implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * An UDP connection listener
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UdpListener extends BaseListener implements Listenable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set the protocol to UDP
- $this->setProtocolName('udp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $nodeInstance A NodeHelper instance
- * @return $listenerInstance An instance a prepared listener class
- */
- public static final function createUdpListener (NodeHelper $nodeInstance) {
- // Get new instance
- $listenerInstance = new UdpListener();
-
- // Return the prepared instance
- return $listenerInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- * @throws InvalidSocketException Thrown if the socket is invalid or an
- * error was detected.
- */
- public function initListener () {
- // Try to open a UDP socket
- $mainSocket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
-
- // Is the socket a valid resource or do we have any error?
- if (!is_resource($mainSocket)) {
- // Then throw an InvalidSocketException
- throw new InvalidSocketException(array($this, $mainSocket), BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
-
- /*
- * "Bind" the socket to the given address, on given port so this means
- * that all connections on this port are now our resposibility to
- * send/recv data, disconnect, etc..
- */
- self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
- if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
- // Handle the socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
- /*
- // Get socket error code for verification
- $socketError = socket_last_error($mainSocket);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($mainSocket);
-
- // And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
-
- // Now, we want non-blocking mode
- self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Setting non-blocking mode.');
- if (!socket_set_nonblock($mainSocket)) {
- // Handle the socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
- /*
- // Get socket error code for verification
- $socketError = socket_last_error($socket);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($mainSocket);
-
- // And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
-
- // Set the option to reuse the port
- self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Setting re-use address option.');
- if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
- // Handle the socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
- /*
- // Get socket error code for verification
- $socketError = socket_last_error($mainSocket);
-
- // Get error message
- $errorMessage = socket_strerror($socketError);
-
- // Shutdown this socket
- $this->shutdownSocket($mainSocket);
-
- // And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
-
- // Remember the socket in our class
- $this->registerServerSocketResource($mainSocket);
-
- // Initialize the network package handler
- $handlerInstance = ObjectFactory::createObjectByConfiguredName('udp_raw_data_handler_class');
-
- // Set it in this class
- $this->setHandlerInstance($handlerInstance);
-
- // Output message
- self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- * @todo ~50% done
- */
- public function doListen() {
- // Read a package and determine the peer
- $amount = @socket_recvfrom($this->getSocketResource(), $rawData, $this->getConfigInstance()->getConfigEntry('udp_buffer_length'), MSG_DONTWAIT, $peer, $port);
-
- // Get last error
- $lastError = socket_last_error($this->getSocketResource());
-
- // Do we have an error at the line?
- if ($lastError == 11) {
- /*
- * This (resource temporary unavailable) can be safely ignored on
- * "listening" UDP ports. If we don't clear the error here, our UDP
- * "listener" won't read any packages except if the UDP sender
- * starts the transmission before this "listener" came up...
- */
- socket_clear_error($this->getSocketResource());
-
- // Skip further processing
- return;
- } elseif ($lastError > 0) {
- // Other error detected
- self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Error detected: ' . socket_strerror($lastError));
-
- // Skip further processing
- return;
- } elseif ((empty($rawData)) || (trim($peer) == '')) {
- // Zero sized packages/peer names are usual in non-blocking mode
- return;
- } // END - if
-
- // Debug only
- self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Handling UDP package with size ' . strlen($rawData) . ' from peer ' . $peer . ':' . $port);
- }
-
- /**
- * Checks whether the listener would accept the given package data array
- *
- * @param $packageData Raw package data
- * @return $accepts Whether this listener does accept
- */
- function ifListenerAcceptsPackageData (array $packageData) {
- $this->partialStub('This call should not happen. Please report it.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A decorator for the UdpListener to communicate to peers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ClientUdpListenerDecorator extends BaseListenerDecorator implements Listenable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set listener type and protocol name
- $this->setListenerType('peer');
- $this->setProtocolName('udp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listenerInstance A Listener instance
- * @return $decoratorInstance An instance a prepared listener decorator class
- */
- public static final function createClientUdpListenerDecorator (Listenable $listenerInstance) {
- // Get new instance
- $decoratorInstance = new ClientUdpListenerDecorator();
-
- // Set the application instance
- $decoratorInstance->setListenerInstance($listenerInstance);
-
- // Return the prepared instance
- return $decoratorInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- */
- public function initListener () {
- $this->partialStub('WARNING: This method should not be called.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- */
- public function doListen () {
- // Handle generic UDP packages first
- $this->getListenerInstance()->doListen();
-
- // Handle this peer UDP package
- $this->partialStub('Need to handle peer UDP package.');
- }
-
- /**
- * Checks whether the listener would accept the given package data array
- *
- * @param $packageData Raw package data
- * @return $accepts Whether this listener does accept
- */
- function ifListenerAcceptsPackageData (array $packageData) {
- // Get a tags instance
- $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
-
- // So is the package accepted with this listener?
- $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
-
- // Return the result
- return $accepts;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A decorator for the UdpListener to communicate to hubs
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubUdpListenerDecorator extends BaseListenerDecorator implements Listenable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set listener type and protocol name
- $this->setListenerType('hub');
- $this->setProtocolName('udp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listenerInstance A Listener instance
- * @return $decoratorInstance An instance a prepared listener decorator class
- */
- public static final function createHubUdpListenerDecorator (Listenable $listenerInstance) {
- // Get new instance
- $decoratorInstance = new HubUdpListenerDecorator();
-
- // Set the application instance
- $decoratorInstance->setListenerInstance($listenerInstance);
-
- // Return the prepared instance
- return $decoratorInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- */
- public function initListener () {
- $this->partialStub('WARNING: This method should not be called.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- */
- public function doListen () {
- // Handle generic UDP package first
- $this->getListenerInstance()->doListen();
-
- // Handle hub UDP package
- $this->partialStub('Need to handle hub UDP package.');
- }
-
- /**
- * Checks whether the listener would accept the given package data array
- *
- * @param $packageData Raw package data
- * @return $accepts Whether this listener does accept
- */
- public function ifListenerAcceptsPackageData (array $packageData) {
- // Get a tags instance
- $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
-
- // So is the package accepted with this listener?
- $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
-
- // Return the result
- return $accepts;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Hub list
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubList extends BaseList implements Listable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $listInstance An instance a Listable class
- */
- public static final function createHubList () {
- // Get new instance
- $listInstance = new HubList();
-
- // Add groups for e.g. connected/disconnected hubs
- $listInstance->addGroup('connected');
- $listInstance->addGroup('disconnected');
-
- // Return the prepared instance
- return $listInstance;
- }
-
- /**
- * "Getter" for an iterator instance of this list (not implemented)
- *
- * @return $iteratorInstance An instance of a Iterator class
- */
- public function getListIterator () {
- $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!');
- }
-
- /**
- * Clears this list by cleaning up all groups together.
- *
- * @return void
- */
- public function clearList () {
- // Clear both groups together
- $this->clearGroups(array('connected', 'disconnected'));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A list for pool entries
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PoolEntriesList extends BaseList implements Listable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $listInstance An instance a Listable class
- */
- public static final function createPoolEntriesList () {
- // Get new instance
- $listInstance = new PoolEntriesList();
-
- // Add 'pool' group
- $listInstance->addGroup('pool');
-
- // Return the prepared instance
- return $listInstance;
- }
-
- /**
- * "Getter" for an iterator instance of this list
- *
- * @return $iteratorInstance An instance of a Iterator class
- */
- public function getListIterator () {
- // Get the iterator instance from the factory
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName('node_ping_iterator_class', array($this));
-
- // Rewind it
- $iteratorInstance->rewind();
-
- // ... and return it
- return $iteratorInstance;
- }
-
- /**
- * Clears this list by cleaning up all groups together.
- *
- * @return void
- */
- public function clearList () {
- // Clear the only one group
- $this->clearGroup('pool');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Recipient list
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 RecipientList extends BaseList implements Listable, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $listInstance An instance a Listable class
- */
- public static final function createRecipientList () {
- // Get new instance
- $listInstance = new RecipientList();
-
- // Add groups:
- // 1.) Universal Node Locators
- $listInstance->addGroup('unl');
-
- // 2.) Session ids
- $listInstance->addGroup('session_id');
-
- // Return the prepared instance
- return $listInstance;
- }
-
- /**
- * "Getter" for an iterator instance of this list (not implemented)
- *
- * @return $iteratorInstance An instance of a Iterator class
- */
- public function getListIterator () {
- $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!');
- }
-
- /**
- * Clears this list by cleaning up all groups together.
- *
- * @return void
- */
- public function clearList () {
- // Clear both groups
- $this->clearGroups(array('unl', 'session_id'));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? menu class for Ship-Simu
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Hub???Menu extends BaseMenu implements RenderableMenu {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $menuInstance An instance of this class
- */
- public final static function createHub???Menu () {
- // Get a new instance
- $menuInstance = new Hub???Menu();
-
- // Return the prepared instance
- return $menuInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A menu class for Hub
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2015 2007 - 2008 Roland Haeder, 2009 - 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 HubIndexMenu extends BaseMenu implements RenderableMenu {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $menuInstance An instance of this class
- */
- public static final function createHubIndexMenu () {
- // Get a new instance
- $menuInstance = new HubIndexMenu();
-
- // Return the prepared instance
- return $menuInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A hub-mcrypt miner class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 HubCoinMiner extends BaseHubMiner implements MinerHelper, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set version number
- $this->setVersion('0.0.0');
- }
-
- /**
- * Creates an instance of this hub-miner class
- *
- * @return $minerInstance An instance of this hub-miner class
- */
- public final static function createHubCoinMiner () {
- // Get a new instance
- $minerInstance = new HubCoinMiner();
-
- // Return the instance
- return $minerInstance;
- }
-
- /**
- * This method fills the in-buffer with (a) test unit(s) which are mainly
- * used for development of the crunching part. They must be enabled in
- * configuration, or else your miner runs out of WUs and waits for more
- * to show up.
- *
- * In this method we already know that the in-buffer is going depleted so
- * no need to double-check it here.
- *
- * @return void
- */
- protected function fillInBufferQueueWithTestUnits () {
- // Are test units enabled?
- if ($this->getConfigInstance()->getConfigEntry('miner_test_units_enabled') == 'N') {
- // They are disabled, so skip any further steps
- return;
- } elseif ($this->getStateInstance()->isMinerStateVirgin()) {
- // No virgin miners please, because they usually have no test units ready for crunching
- return;
- }
-
- // Get a test-unit generator instance
- $generatorInstance = ObjectFactory::createObjectByConfiguredName('miner_test_unit_generator_class');
-
- // We don't need an iterator here because we just need to generate some test units
- for ($idx = 0; $idx < $this->getConfigInstance()->getConfigEntry('miner_max_text_unit_amount'); $idx++) {
- // Get a test unit from it
- $unitInstance = $generatorInstance->generateNextUnitInstance();
-
- // ... and finally queue it to the in-buffer queue
- $this->queueUnitInstanceToInBuffer($unitInstance);
- } // END - for
- }
-
- /**
- * This method fills the in-buffer with (real) WUs which will be crunched
- * and the result be sent back to the key producer instance.
- *
- * @return void
- */
- protected function fillInBufferQueueWithWorkUnits () {
- // This miner's state must not be one of these: 'virgin'
- if ($this->getStateInstance()->isMinerStateVirgin()) {
- // We can silently skip here, until the generation is finished
- return;
- } // END - if
-
- // @TODO Implement this method
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Method to "bootstrap" the miner. This step does also apply provided
- * command-line arguments stored in the request instance. No buffer queue
- * will be initialized here, we only do "general" things here.
- *
- * @return void
- * @todo Implement this method
- */
- public function doBootstrapping () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- // Output all lines
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput('Hubcoin miner v' . $this->getVersion() . ' is starting ...');
- self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2014 Miner Developer Team');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
- self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
- self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- }
-
- /**
- * Add some miner-specific filters
- *
- * @param $controllerInstance An object of a Controller instance
- * @param $responseInstance An object of a Responseable instance
- * @return void
- * @todo 0% done
- */
- public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) {
- // Add some filters here
- $this->partialStub('Please add some miner-specific filters, if required.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A hub-miner class for the '???' mode
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Hub???Miner extends BaseHubMiner implements MinerHelper, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set version number
- $this->setVersion('x.x');
- }
-
- /**
- * Creates an instance of this hub-miner class
- *
- * @param $requestInstance An instance of a Requestable class
- * @return $minerInstance An instance of this hub-miner class
- */
- public final static function createHub???Miner (Requestable $requestInstance) {
- // Get a new instance
- $minerInstance = new Hub???Miner();
-
- // Set the request instance
- $minerInstance->setRequestInstance($requestInstance);
-
- // Return the instance
- return $minerInstance;
- }
-
- /**
- * Method to "bootstrap" the miner. This step does also apply provided
- * command-line arguments stored in the request instance. The regular miner
- * should communicate with the bootstrap-miners at this point.
- *
- * @return void
- * @todo Implement this method
- */
- public function doBootstrapping () {
- // Call generic (parent) bootstrapping method first
- parent::doGenericBootstrapping();
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Add some miner-specific filters
- *
- * @return void
- */
- public function addExtraHubFilters () {
- // Add some filters here
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general hub miner class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Miner 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/>.
- */
-abstract class BaseHubMiner extends BaseHubSystem implements Updateable {
- /**
- * Version information
- */
- private $version = 'x.x';
-
- /**
- * By default no miner is active
- */
- private $isActive = FALSE;
-
- /**
- * All buffer queue instances (a FIFO)
- */
- private $bufferInstance = NULL;
-
- /**
- * An array for initialized producers
- */
- private $producersInitialized = array();
-
- /**
- * Stacker name for incoming queue
- */
- const STACKER_NAME_IN_QUEUE = 'in_queue';
-
- /**
- * Stacker name for outcoming queue
- */
- const STACKER_NAME_OUT_QUEUE = 'out_queue';
-
- /**
- * Maximum number of producers (2: test and real)
- */
- const MAX_PRODUCERS = 2;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Init this miner
- $this->initMiner();
- }
-
- /**
- * Initialize the miner generically
- *
- * @return void
- */
- private function initMiner () {
- // Add own instance to registry
- Registry::getRegistry()->addInstance('miner', $this);
-
- // Init the state
- MinerStateFactory::createMinerStateInstanceByName('init');
- }
-
- /**
- * Getter for version
- *
- * @return $version Version number of this miner
- */
- protected final function getVersion () {
- return $this->version;
- }
-
- /**
- * Setter for version
- *
- * @param $version Version number of this miner
- * @return void
- */
- protected final function setVersion ($version) {
- $this->version = (string) $version;
- }
-
- /**
- * Checks whether the in-buffer queue is filled by comparing it's current
- * amount of entries against a threshold.
- *
- * @return $isFilled Whether the in-buffer is filled
- */
- protected function isInBufferQueueFilled () {
- // Determine it
- $isFilled = ($this->bufferInstance->getStackCount(self::STACKER_NAME_IN_QUEUE) > $this->getConfigInstance()->getConfigEntry('miner_in_buffer_min_threshold'));
-
- // And return the result
- return $isFilled;
- }
-
- /**
- * This method fills the in-buffer with (a) test unit(s) which are mainly
- * used for development of the crunching part. They must be enabled in
- * configuration, or else your miner runs out of WUs and waits for more
- * to show up.
- *
- * In this method we already know that the in-buffer is going depleted so
- * no need to double-check it here.
- *
- * @return void
- */
- abstract protected function fillInBufferQueueWithTestUnits ();
-
- /**
- * This method fills the in-buffer with (real) WUs which will be crunched
- * and the result be sent back to the key producer instance.
- *
- * @return void
- */
- abstract protected function fillInBufferQueueWithWorkUnits ();
-
- /**
- * Enables/disables the miner (just sets a flag)
- *
- * @param $version Version number of this miner
- * @return void
- */
- public final function enableIsActive ($isActive = TRUE) {
- $this->isActive = (bool) $isActive;
- }
-
- /**
- * Determines whether the miner is active
- *
- * @return $isActive Whether the miner is active
- */
- public final function isActive () {
- return $this->isActive;
- }
-
- /**
- * Initializes all buffer queues (mostly in/out). This method is demanded
- * by the MinerHelper interface.
- *
- * @return void
- */
- public function initBufferQueues () {
- /*
- * Initialize both buffer queues, we can use the FIFO class here
- * directly and encapsulate its method calls with protected methods.
- */
- $this->bufferInstance = ObjectFactory::createObjectByConfiguredName('miner_buffer_stacker_class');
-
- // Initialize common stackers, like in/out
- $this->bufferInstance->initStacks(array(
- self::STACKER_NAME_IN_QUEUE,
- self::STACKER_NAME_OUT_QUEUE
- ));
-
- // Output debug message
- self::createDebugInstance(__CLASS__)->debugOutput('MINER: All buffers are now initialized.');
- }
-
- /**
- * This method determines if the in-buffer is going to depleted and if so,
- * it fetches more WUs from the network. If no WU can be fetched from the
- * network and if enabled, a random test WU is being generated.
- *
- * This method is demanded from the MinerHelper interface.
- *
- * @return void
- */
- public function doFetchWorkUnits () {
- // Simply check if we have enough WUs left in the in-buffer queue (a FIFO)
- if (!$this->isInBufferQueueFilled()) {
- // The in-buffer queue needs filling, so head out and get some work
- $this->fillInBufferQueueWithWorkUnits();
-
- // Is the buffer still not filled and are test-packages allowed?
- if ((!$this->isInBufferQueueFilled()) && ($this->getConfigInstance()->getConfigEntry('miner_test_units_enabled') == 'Y')) {
- // Then fill the in-buffer with (one) test-unit(s)
- $this->fillInBufferQueueWithTestUnits();
- } // END - if
- } // END - if
- }
-
- /**
- * Updates a given field with new value
- *
- * @param $fieldName Field to update
- * @param $fieldValue New value to store
- * @return void
- * @throws DatabaseUpdateSupportException If this class does not support database updates
- * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
- */
- public function updateDatabaseField ($fieldName, $fieldValue) {
- // Unfinished
- $this->partialStub('Unfinished!');
- return;
- }
-
- /**
- * Changes the state to 'booting' and shall be called after the block
- * producer has been initialized.
- *
- * @param $producerInstance An instance of a BlockProducer class
- * @return void
- */
- public function blockProducerHasInitialized (BlockProducer $producerInstance) {
- // Make sure the state is correct ('init')
- $this->getStateInstance()->validateMinerStateIsInit();
-
- // Mark given producer as initialized
- $this->producersInitialized[$producerInstance->__toString()] = TRUE;
-
- // Has all producers been initialized?
- if (count($this->producersInitialized) == self::MAX_PRODUCERS) {
- // Change it to 'booting'
- MinerStateFactory::createMinerStateInstanceByName('booting');
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A hub-node class for the 'Boot' mode
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubBootNode extends BaseHubNode implements NodeHelper, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this hub-node class
- *
- * @param $requestInstance An instance of a Requestable class
- * @return $nodeInstance An instance of this hub-node class
- */
- public static final function createHubBootNode (Requestable $requestInstance) {
- // Get a new instance
- $nodeInstance = new HubBootNode();
-
- // Set the request instance
- $nodeInstance->setRequestInstance($requestInstance);
-
- // Return the instance
- return $nodeInstance;
- }
-
- /**
- * Method to "bootstrap" the node. This step does also apply provided
- * command-line arguments stored in the request instance. The regular node
- * should communicate with the bootstrap-nodes at this point.
- *
- * @return void
- * @todo add some more special bootstrap things for this boot node
- */
- public function doBootstrapping () {
- // Get UNL
- $unl = $this->detectOwnUniversalNodeLocator();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl);
-
- // Now check if the IP address matches one of the bootstrap nodes
- if ($this->ifAddressMatchesBootstrapNodes($unl)) {
- // Get our port from configuration
- $ourPort = $this->getConfigInstance()->getConfigEntry('node_listen_port');
-
- // Extract port
- $bootPort = substr($this->getBootUniversalNodeLocator(), -strlen($ourPort), strlen($ourPort));
-
- // Is the port the same?
- if ($bootPort == $ourPort) {
- // It is the same!
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: UNL matches bootstrap node ' . $this->getBootUniversalNodeLocator() . '.');
-
- // Now, does the mode match
- if ($this->getRequestInstance()->getRequestElement('mode') == self::NODE_TYPE_BOOT) {
- // Output debug message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Our node is a valid bootstrap node.');
- } else {
- // Output warning
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Mismatching mode ' . $this->getRequestInstance()->getRequestElement('mode') . '!=' . BaseHubNode::NODE_TYPE_BOOT . ' detected.');
- }
- } else {
- // IP does match, but no port
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.');
- }
- } else {
- // Node does not match any know bootstrap-node
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does not match any known bootstrap-nodes.');
- }
-
- // Enable acceptance of announcements
- $this->enableAcceptingAnnouncements();
-
- // This might not be all...
- $this->partialStub('Please implement more bootsrapping steps.');
- }
-
- /**
- * Add some node-specific filters
- *
- * @return void
- */
- public function addExtraNodeFilters () {
- // Get the application instance from registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Get the controller from the application
- $controllerInstance = $applicationInstance->getControllerInstance();
-
- // @TODO Add some filters here
- $this->partialStub('Add some filters here.');
- }
-
- /**
- * Adds extra tasks to the given handler for this node
- *
- * @param $handlerInstance An instance of a HandleableTask class
- * @return void
- */
- public function addExtraTasks (HandleableTask $handlerInstance) {
- // Prepare a task for booting the DHT
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_bootstrap_task_class');
-
- // Register it
- $handlerInstance->registerTask('dht_bootstrap', $taskInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-
- /**
- * Adds extra tasks to the given handler for this node
- *
- * @param $handlerInstance An instance of a HandleableTask class
- * @return void
- * @todo 0% done
- */
- public function addExtraTasks (HandleableTask $handlerInstance) {
- $this->partialStub('Please add some tasks or empty this method.');
- }
+++ /dev/null
-<?php
-/**
- * A hub-node class for the '???' mode
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Hub???Node extends BaseHubNode implements NodeHelper, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this hub-node class
- *
- * @param $requestInstance An instance of a Requestable class
- * @return $nodeInstance An instance of this hub-node class
- */
- public final static function createHub???Node (Requestable $requestInstance) {
- // Get a new instance
- $nodeInstance = new Hub???Node();
-
- // Set the request instance
- $nodeInstance->setRequestInstance($requestInstance);
-
- // Return the instance
- return $nodeInstance;
- }
-
- /**
- * Method to "bootstrap" the node. This step does also apply provided
- * command-line arguments stored in the request instance. The regular node
- * should communicate with the bootstrap-nodes at this point.
- *
- * @return void
- * @todo Implement this method
- */
- public function doBootstrapping () {
- // Call generic (parent) bootstrapping method first
- parent::doGenericBootstrapping();
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Initializes hub-specific queues
- *
- * @return void
- * @todo Implement this method
- */
- public function initQueues () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Add some node-specific filters
- *
- * @return void
- */
- public function addExtraHubFilters () {
- // Add some filters here
- }
-
- /**
- * Adds extra tasks to the given handler for this node
- *
- * @param $handlerInstance An instance of a HandleableTask class
- * @return void
- * @todo 0% done
- */
- public function addExtraTasks (HandleableTask $handlerInstance) {
- $this->partialStub('Please add some tasks or empty this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general hub node class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
- /**
- * Node types
- */
- const NODE_TYPE_BOOT = 'boot';
- const NODE_TYPE_MASTER = 'master';
- const NODE_TYPE_LIST = 'list';
- const NODE_TYPE_REGULAR = 'regular';
-
- // Exception constants
- const EXCEPTION_HUB_ALREADY_ANNOUNCED = 0xe00;
-
- // Other constants
- const OBJECT_LIST_SEPARATOR = ',';
-
- /**
- * Universal node locator of bootstrap node
- */
- private $bootUnl = '';
-
- /**
- * Whether this node is anncounced (keep on FALSE!)
- * @deprecated
- */
- private $hubIsAnnounced = FALSE;
-
- /**
- * Whether this hub is active (default: FALSE)
- */
- private $isActive = FALSE;
-
- /**
- * Whether this node accepts announcements (default: FALSE)
- */
- private $acceptAnnouncements = FALSE;
-
- /**
- * Whether this node accepts DHT bootstrap requests (default: FALSE)
- */
- private $acceptDhtBootstrap = FALSE;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Get a wrapper instance
- $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_info_db_wrapper_class');
-
- // Set it here
- $this->setWrapperInstance($wrapperInstance);
-
- // Get a crypto instance
- $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
-
- // Set it here
- $this->setCryptoInstance($cryptoInstance);
-
- // Set the node instance in registry
- Registry::getRegistry()->addInstance('node', $this);
-
- // Init state which sets the state to 'init'
- $this->initState();
- }
-
- /**
- * Initializes the node's state which sets it to 'init'
- *
- * @return void
- */
- private function initState() {
- // Get the state factory and create the initial state.
- NodeStateFactory::createNodeStateInstanceByName('init');
- }
-
- /**
- * Generates a private key and hashes it (for speeding up things)
- *
- * @param $searchInstance An instance of a LocalSearchCriteria class
- * @return void
- */
- private function generatePrivateKeyAndHash (LocalSearchCriteria $searchInstance) {
- // Get an RNG instance
- $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
-
- // Generate a pseudo-random string
- $randomString = $rngInstance->randomString(255);
-
- // Hash and encrypt the string so we become a node id (also documented as "hub id")
- $this->setPrivateKey($this->getCryptoInstance()->encryptString($randomString));
- $this->setPrivateKeyHash($this->getCryptoInstance()->hashString($this->getPrivateKey()));
-
- // Register the node id with our wrapper
- $this->getWrapperInstance()->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance);
-
- // Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . '');
- }
-
- /**
- * Generates a random string from various data inluding UUID if PECL
- * extension uuid is installed.
- *
- * @param $length Length of the random part
- * @return $randomString Random string
- * @todo Make this code more generic and move it to CryptoHelper or
- */
- protected function generateRamdomString ($length) {
- // Get an RNG instance
- $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
-
- // Generate a pseudo-random string
- $randomString = $rngInstance->randomString($length) . ':' . $this->getBootUniversalNodeLocator() . ':' . $this->getRequestInstance()->getRequestElement('mode');
-
- // Add UUID for even more entropy for the hasher
- $randomString .= $this->getCryptoInstance()->createUuid();
-
- // Return it
- return $randomString;
- }
-
- /**
- * Getter for boot UNL (Universal Node Locator)
- *
- * @return $bootUnl The UNL (Universal Node Locator) of the boot node
- */
- protected final function getBootUniversalNodeLocator () {
- return $this->bootUnl;
- }
-
- /**
- * Checks whether the given IP address matches one of the bootstrap nodes
- *
- * @param $remoteAddr IP address to checkout against our bootstrapping list
- * @return $isFound Whether the IP is found
- */
- protected function ifAddressMatchesBootstrapNodes ($remoteAddr) {
- // By default nothing is found
- $isFound = FALSE;
-
- // Run through all configured IPs
- foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) {
- // Does it match?
- if ($unl == $remoteAddr) {
- // Found it!
- $isFound = TRUE;
-
- // Remember the UNL
- $this->bootUnl = $unl;
-
- // Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: UNL matches remote address ' . $unl . '.');
-
- // Stop further searching
- break;
- } elseif ($unl == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
- /*
- * IP matches listen address. At this point we really don't care
- * if we can really listen on that address
- */
- $isFound = TRUE;
-
- // Remember the port number
- $this->bootUnl = $unl;
-
- // Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: UNL matches listen address ' . $unl . '.');
-
- // Stop further searching
- break;
- }
- } // END - foreach
-
- // Return the result
- return $isFound;
- }
-
- /**
- * Tries to detect own UNL (Universal Node Locator)
- *
- * @return $unl Node's own universal node locator
- */
- public function detectOwnUniversalNodeLocator () {
- // Is "cache" set?
- if (!isset($GLOBALS[__METHOD__])) {
- // Get the UNL array back
- $unlData = $this->getUniversalNodeLocatorArray();
-
- // There are 2 UNLs, internal and external.
- if ($this->getConfigInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
- // Public "external" UNL address
- $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL];
- } else {
- // Non-public "internal" UNL address
- $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL];
- }
- } // END - if
-
- // Return it
- return $GLOBALS[__METHOD__];
- }
-
- /**
- * Outputs the console teaser. This should only be executed on startup or
- * full restarts. This method generates some space around the teaser.
- *
- * @return void
- */
- public function outputConsoleTeaser () {
- // Get the app instance (for shortening our code)
- $app = $this->getApplicationInstance();
-
- // Output all lines
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
- self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2015 Hub Developer Team');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
- self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
- self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
- self::createDebugInstance(__CLASS__)->debugOutput(' ');
- }
-
- /**
- * Generic method to acquire a hub-id. On first run this generates a new one
- * based on many pseudo-random data. On any later run, unless the id
- * got not removed from database, it will be restored from the database.
- *
- * @param $requestInstance A Requestable class
- * @param $responseInstance A Responseable class
- * @return void
- */
- public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
- // Is there a node id?
- if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
- // Get the node id from result and set it
- $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
-
- // Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
- } else {
- // Get an RNG instance
- $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
-
- // Generate a pseudo-random string
- $randomString = $rngInstance->randomString(255);
-
- // Hash and encrypt the string so we become a node id (also documented as "hub id")
- $this->setNodeId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
-
- // Register the node id with our wrapper
- $this->getWrapperInstance()->registerNodeId($this, $this->getRequestInstance());
-
- // Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . '');
- }
- }
-
- /**
- * Generates a session id which will be sent to the other hubs and peers
- *
- * @return void
- */
- public function bootstrapGenerateSessionId () {
- // Now get a search criteria instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Search for the node number one which is hard-coded the default
- $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
- $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $this->getRequestInstance()->getRequestElement('mode'));
- $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID , $this->getNodeId());
- $searchInstance->setLimit(1);
-
- // Remember it for later usage
- $this->setSearchInstance($searchInstance);
-
- // Get a random string
- $randomString = $this->generateRamdomString(255);
-
- // Hash and encrypt the string so we become a "node id" aka Hub-Id
- $this->setSessionId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
-
- // Register the node id with our wrapper
- $this->getWrapperInstance()->registerSessionId($this, $this->getRequestInstance(), $searchInstance);
-
- // Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
-
- // Change the state because the node has aquired a session id
- $this->getStateInstance()->nodeGeneratedSessionId();
- }
-
- /**
- * Generate a private key for en-/decryption
- *
- * @return void
- */
- public function bootstrapGeneratePrivateKey () {
- // Is it valid?
- if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
- // Is the element set?
- if (is_null($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))) {
- /*
- * Auto-generate the private key for e.g. out-dated database
- * "tables". This allows a smooth update for the underlaying
- * database table.
- */
- $this->generatePrivateKeyAndHash($this->getSearchInstance());
- } else {
- // Get the node id from result and set it
- $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY)));
- $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH));
-
- // Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . '');
- }
- } else {
- /*
- * Generate it in a private method (no confusion with 'private
- * method access' and 'private key' here! ;-)).
- */
- $this->generatePrivateKeyAndHash($this->getSearchInstance());
- }
- }
-
- /**
- * Adds hub data elements to a given dataset instance
- *
- * @param $criteriaInstance An instance of a storeable criteria
- * @param $requestInstance An instance of a Requestable class
- * @return void
- */
- public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
- // Make sure the request instance is set as it is not optional.
- assert($requestInstance instanceof Requestable);
-
- // Add node number and type
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $requestInstance->getRequestElement('mode'));
-
- // Add the node id
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());
-
- // Add the session id if acquired
- if ($this->getSessionId() != '') {
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId());
- } // END - if
-
- // Add the private key if acquired
- if ($this->getPrivateKey() != '') {
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey()));
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash());
- } // END - if
-
- // Add own external and internal addresses as UNLs
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, HubTools::determineOwnInternalAddress());
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL, HubTools::determineOwnExternalAddress());
- }
-
- /**
- * Updates a given field with new value
- *
- * @param $fieldName Field to update
- * @param $fieldValue New value to store
- * @return void
- * @throws DatabaseUpdateSupportException If this class does not support database updates
- * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
- */
- public function updateDatabaseField ($fieldName, $fieldValue) {
- // Unfinished
- $this->partialStub('Unfinished!');
- return;
-
- // Get a critieria instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Add search criteria
- $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
- $searchInstance->setLimit(1);
-
- // Now get another criteria
- $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
-
- // Add criteria entry which we shall update
- $updateInstance->addCriteria($fieldName, $fieldValue);
-
- // Add the search criteria for searching for the right entry
- $updateInstance->setSearchInstance($searchInstance);
-
- // Set wrapper class name
- $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
-
- // Remember the update in database result
- $this->getResultInstance()->add2UpdateQueue($updateInstance);
- }
-
- /**
- * Announces this hub to the upper (bootstrap or list) hubs. After this is
- * 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
- * @throws NodeAlreadyAnnouncedException If this hub is already announced
- * @todo Change the first if() block to check for a specific state
- */
- public function announceToUpperNodes (Taskable $taskInstance) {
- // Is this hub node announced?
- if ($this->hubIsAnnounced === TRUE) {
- // Already announced!
- throw new NodeAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
- } // END - if
-
- // Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
-
- // Get a helper instance
- $helperInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_helper_class');
-
- // Load the announcement descriptor
- $helperInstance->loadDescriptorXml($this);
-
- // Compile all variables
- $helperInstance->getTemplateInstance()->compileConfigInVariables();
-
- // "Publish" the descriptor by sending it to the bootstrap/list nodes
- $helperInstance->sendPackage($this);
-
- // Change the state, this should be the last line except debug output
- $this->getStateInstance()->nodeAnnouncingToUpperHubs();
-
- // Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-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
- self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
-
- // Get a helper instance
- $helperInstance = ObjectFactory::createObjectByConfiguredName('node_self_connect_helper_class', array($this));
-
- // Load the descriptor (XML) file
- $helperInstance->loadDescriptorXml($this);
-
- // Compile all variables
- $helperInstance->getTemplateInstance()->compileConfigInVariables();
-
- // And send the package away
- $helperInstance->sendPackage($this);
-
- // Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: FINISHED');
- }
-
- /**
- * Activates the hub by doing some final preparation and setting
- * $hubIsActive to TRUE.
- *
- * @param $requestInstance A Requestable class
- * @param $responseInstance A Responseable class
- * @return void
- */
- public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
- // Checks whether a listener is still active and shuts it down if one
- // is still listening.
- if (($this->determineIfListenerIsActive()) && ($this->isNodeActive())) {
- // Shutdown them down before they can hurt anything
- $this->shutdownListenerPool();
- } // END - if
-
- // Get the controller here
- $controllerInstance = Registry::getRegistry()->getInstance('controller');
-
- // Run all filters for the hub activation
- $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
-
- // ----------------------- Last step from here ------------------------
- // Activate the hub. This is ALWAYS the last step in this method
- $this->getStateInstance()->nodeIsActivated();
- // ---------------------- Last step until here ------------------------
- }
-
- /**
- * Initializes the listener pool (class)
- *
- * @return void
- */
- public function initializeListenerPool () {
- // Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: START');
-
- // Get a new pool instance
- $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)));
-
- // Get an instance of the low-level listener
- $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this));
-
- // Setup address and port
- $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
-
- /*
- * All nodes can now use the same configuration entry because it can be
- * customized in config-local.php.
- */
- $listenerInstance->setListenPortByConfiguration('node_listen_port');
-
- // Initialize the listener
- $listenerInstance->initListener();
-
- // Get a decorator class
- $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_tcp_listener_class', array($listenerInstance));
-
- // Add this listener to the pool
- $this->getListenerPoolInstance()->addListener($decoratorInstance);
-
- // Get a decorator class
- $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
-
- // Add this listener to the pool
- $this->getListenerPoolInstance()->addListener($decoratorInstance);
-
- // Get an instance of the low-level listener
- $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this));
-
- // Setup address and port
- $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
-
- /*
- * All nodes can now use the same configuration entry because it can be
- * customized in config-local.php.
- */
- $listenerInstance->setListenPortByConfiguration('node_listen_port');
-
- // Initialize the listener
- $listenerInstance->initListener();
-
- // Get a decorator class
- $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_udp_listener_class', array($listenerInstance));
-
- // Add this listener to the pool
- $this->getListenerPoolInstance()->addListener($decoratorInstance);
-
- // Get a decorator class
- $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
-
- // Add this listener to the pool
- $this->getListenerPoolInstance()->addListener($decoratorInstance);
-
- // Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: FINISHED.');
- }
-
- /**
- * Getter for isActive attribute
- *
- * @return $isActive Whether the hub is active
- */
- public final function isNodeActive () {
- return $this->isActive;
- }
-
- /**
- * Enables (default) or disables isActive flag
- *
- * @param $isActive Whether the hub is active
- * @return void
- */
- public final function enableIsActive ($isActive = TRUE) {
- $this->isActive = (bool) $isActive;
- }
-
- /**
- * Checks whether this node accepts announcements
- *
- * @return $acceptAnnouncements Whether this node accepts announcements
- */
- public final function isAcceptingAnnouncements () {
- // Check it (this node must be active and not shutdown!)
- $acceptAnnouncements = (($this->acceptAnnouncements === TRUE) && ($this->isNodeActive()));
-
- // Return it
- return $acceptAnnouncements;
- }
-
- /**
- * Checks whether this node accepts DHT bootstrap requests
- *
- * @return $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests
- */
- public final function isAcceptingDhtBootstrap () {
- // Check it (this node must be active and not shutdown!)
- $acceptDhtBootstrap = (($this->acceptDhtBootstrap === TRUE) && ($this->isNodeActive()));
-
- // Return it
- return $acceptDhtBootstrap;
- }
-
- /**
- * Checks whether this node has attempted to announce itself
- *
- * @return $hasAnnounced Whether this node has attempted to announce itself
- * @todo Add checking if this node has been announced to the sender node
- */
- public function ifNodeIsAnnouncing () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeIsAnnouncing(): state=' . $this->getStateInstance()->getStateName());
-
- // Simply check the state of this node
- $hasAnnounced = ($this->getStateInstance() instanceof NodeAnnouncingState);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeIsAnnouncing(): hasAnnounced=' . intval($hasAnnounced));
-
- // Return it
- return $hasAnnounced;
- }
-
- /**
- * Checks whether this node has attempted to announce itself and completed it
- *
- * @return $hasAnnouncementCompleted Whether this node has attempted to announce itself and completed it
- * @todo Add checking if this node has been announced to the sender node
- */
- public function ifNodeHasAnnouncementCompleted () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): state=' . $this->getStateInstance()->getStateName());
-
- // Simply check the state of this node
- $hasAnnouncementCompleted = ($this->getStateInstance() instanceof NodeAnnouncementCompletedState);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): hasAnnouncementCompleted=' . intval($hasAnnouncementCompleted));
-
- // Return it
- return $hasAnnouncementCompleted;
- }
-
- /**
- * Enables whether this node accepts announcements
- *
- * @param $acceptAnnouncements Whether this node accepts announcements (default: TRUE)
- * @return void
- */
- protected final function enableAcceptingAnnouncements ($acceptAnnouncements = TRUE) {
- $this->acceptAnnouncements = $acceptAnnouncements;
- }
-
- /**
- * Enables whether this node accepts DHT bootstrap requests
- *
- * @param $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests (default: TRUE)
- * @return void
- */
- public final function enableAcceptDhtBootstrap ($acceptDhtBootstrap = TRUE) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...');
- $this->acceptDhtBootstrap = $acceptDhtBootstrap;
- }
-
- /**
- * Checks wether this node is accepting node-list requests
- *
- * @return $acceptsRequest Wether this node accepts node-list requests
- */
- public function isAcceptingNodeListRequests () {
- /*
- * Only 'regular' nodes does not accept such requests, checking
- * HubRegularNode is faster, but if e.g. HubRegularI2PNode will be
- * added then the next check will be TRUE.
- */
- $acceptsRequest = ((!$this instanceof HubRegularNode) && ($this->getRequestInstance()->getRequestElement('mode') != self::NODE_TYPE_REGULAR));
-
- // Return it
- return $acceptsRequest;
- }
-
- /**
- * Determines an instance of a LocateableNode class
- *
- * @return $unlInstance An instance of a LocateableNode class for this node
- */
- public function determineUniversalNodeLocator () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Determine UNL based on this node:
- // 1) Get discovery class
- $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
-
- // 2) "Determine" it
- $unlInstance = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
-
- // 3) Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unlInstance= ' . $unlInstance->__toString() . ' - EXIT!');
- return $unlInstance;
- }
-
- /**
- * "Getter" for an array of an instance of a LocateableNode class
- *
- * @return $unlData An array from an instance of a LocateableNode class for this node
- */
- public final function getUniversalNodeLocatorArray () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Get the Universal Node Locator (UNL) instance
- $unlInstance = $this->determineUniversalNodeLocator();
-
- // Make sure the instance is valid
- if (!$unlInstance instanceof LocateableNode) {
- // No valid instance, so better debug this
- $this->debugBackTrace('unlInstance[' . gettype($unlInstance) . ']=' . $unlInstance);
- } // END - if
-
- // ... and the array from it
- $unlData = $unlInstance->getUnlData();
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- return $unlData;
- }
-
- /**
- * Updates/refreshes node data (e.g. status).
- *
- * @return void
- * @todo Find more to do here
- */
- public function updateNodeData () {
- // Set some dummy configuration entries, e.g. node_status
- $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
- }
-
- /**
- * Handles message answer by given data array
- *
- * @param $messageData A valid answer message data array
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @todo Handle thrown exception
- */
- public function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance) {
- // Is it not empty?
- assert(!empty($messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]));
-
- // Construct configuration entry for handling class' name
- $classConfigEntry = strtolower($messageData[NetworkPackage::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]) . '_handler_class';
-
- // Try to get a class
- $handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
-
- // Handle it there
- $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
- }
-
- /**
- * "Getter" for an array of all accepted object types
- *
- * @return $objectList Array of all accepted object types
- */
- public function getListFromAcceptedObjectTypes () {
- // Get registry instance
- $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
-
- // Get all entries
- $objectList = $objectRegistryInstance->getEntries(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME);
-
- // ... and return it
- return $objectList;
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $nodeData An array with valid node data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $nodeData) {
- // Add all data the array provides
- foreach (NodeDistributedHashTableDatabaseWrapper::getAllElements() as $element) {
- // Is the element there?
- if (isset($nodeData[$element])) {
- // Add it
- $dataSetInstance->addCriteria($element, $nodeData[$element]);
- } else {
- // Output warning message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: addArrayToDataSet(): Element ' . $element . ' not found in nodeData array.');
- }
- } // END - foreac
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A hub-node class for the 'List' mode
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubListNode extends BaseHubNode implements NodeHelper, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this hub-node class
- *
- * @param $requestInstance An instance of a Requestable class
- * @return $nodeInstance An instance of this hub-node class
- */
- public static final function createHubListNode (Requestable $requestInstance) {
- // Get a new instance
- $nodeInstance = new HubListNode();
-
- // Set the request instance
- $nodeInstance->setRequestInstance($requestInstance);
-
- // Return the instance
- return $nodeInstance;
- }
-
- /**
- * Method to "bootstrap" the node. This step does also apply provided
- * command-line arguments stored in the request instance. The regular node
- * should communicate with the bootstrap-nodes at this point.
- *
- * @return void
- * @todo Implement more bootstrap steps
- */
- public function doBootstrapping () {
- $this->partialStub();
- }
-
- /**
- * Add some node-specific filters
- *
- * @return void
- */
- public function addExtraNodeFilters () {
- // Get the application instance from registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Get the controller from the application
- $controllerInstance = $applicationInstance->getControllerInstance();
-
- // Self-announcement task
- $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_announcement_task_filter'));
-
- // @TODO Add some filters here
- $this->partialStub('Add some filters here.');
- }
-
- /**
- * Adds extra tasks to the given handler for this node
- *
- * @param $handlerInstance An instance of a HandleableTask class
- * @return void
- * @todo 0% done
- */
- public function addExtraTasks (HandleableTask $handlerInstance) {
- $this->partialStub('Please add some tasks or empty this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A hub-node class for the 'Master' mode
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubMasterNode extends BaseHubNode implements NodeHelper, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this hub-node class
- *
- * @param $requestInstance An instance of a Requestable class
- * @return $nodeInstance An instance of this hub-node class
- */
- public static final function createHubMasterNode (Requestable $requestInstance) {
- // Get a new instance
- $nodeInstance = new HubMasterNode();
-
- // Set the request instance
- $nodeInstance->setRequestInstance($requestInstance);
-
- // Return the instance
- return $nodeInstance;
- }
-
- /**
- * Method to "bootstrap" the node. This step does also apply provided
- * command-line arguments stored in the request instance. The regular node
- * should communicate with the bootstrap-nodes at this point.
- *
- * @return void
- * @todo Implement this method
- */
- public function doBootstrapping () {
- // Enable acceptance of announcements
- $this->enableAcceptingAnnouncements();
-
- // Do more steps
- $this->partialStub('Please implement more boot-strapping steps!');
- }
-
- /**
- * Add some node-specific filters
- *
- * @return void
- */
- public function addExtraNodeFilters () {
- // Get the application instance from registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Get the controller from the application
- $controllerInstance = $applicationInstance->getControllerInstance();
-
- // Self-announcement task
- $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_announcement_task_filter'));
-
- // @TODO Add some filters here
- $this->partialStub('Add some filters here.');
- }
-
- /**
- * Adds extra tasks to the given handler for this node
- *
- * @param $handlerInstance An instance of a HandleableTask class
- * @return void
- * @todo 0% done
- */
- public function addExtraTasks (HandleableTask $handlerInstance) {
- $this->partialStub('Please add some tasks or empty this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A hub-node class for the 'regular' mode
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubRegularNode extends BaseHubNode implements NodeHelper, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this hub-node class
- *
- * @param $requestInstance An instance of a Requestable class
- * @return $nodeInstance An instance of this hub-node class
- */
- public static final function createHubRegularNode (Requestable $requestInstance) {
- // Get a new instance
- $nodeInstance = new HubRegularNode();
-
- // Set the request instance
- $nodeInstance->setRequestInstance($requestInstance);
-
- // Return the instance
- return $nodeInstance;
- }
-
- /**
- * Method to "bootstrap" the node. This step does also apply provided
- * command-line arguments stored in the request instance. The regular node
- * should communicate with the bootstrap-nodes at this point.
- *
- * @return void
- * @todo Implement this method
- */
- public function doBootstrapping () {
- $this->partialStub();
- }
-
- /**
- * Add some node-specific filters
- *
- * @return void
- */
- public function addExtraNodeFilters () {
- // Get the application instance from registry
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Get the controller from the application
- $controllerInstance = $applicationInstance->getControllerInstance();
-
- // Self-announcement task
- $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('node_activation_announcement_task_filter'));
-
- // @TODO Add some filters here
- $this->partialStub('Add some filters here.');
- }
-
- /**
- * Adds extra tasks to the given handler for this node
- *
- * @param $handlerInstance An instance of a HandleableTask class
- * @return void
- * @todo 0% done
- */
- public function addExtraTasks (HandleableTask $handlerInstance) {
- $this->partialStub('Please add some tasks or empty this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A PackageAssembler class to assemble a package content stream fragemented
- * by PackageFragmenter back to a raw package data array.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageAssembler extends BaseHubSystem implements Assembler, Registerable, Visitable {
- /**
- * Name for stacker holding raw data of multiple messages
- */
- const STACKER_NAME_MULTIPLE_MESSAGE = 'multiple_message';
-
- /**
- * Pending data
- */
- private $pendingData = '';
-
- /**
- * Private call-back methods
- */
- private $callbacks = array();
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $packageInstance An instance of a Receivable class
- * @return $assemblerInstance An instance of an Assembler class
- */
- public static final function createPackageAssembler (Receivable $packageInstance) {
- // Get new instance
- $assemblerInstance = new PackageAssembler();
-
- // Set package instance here
- $assemblerInstance->setPackageInstance($packageInstance);
-
- // Create an instance of a raw data input stream
- $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class');
-
- // And set it
- $assemblerInstance->setInputStreamInstance($streamInstance);
-
- // Now get a chunk handler instance
- $handlerInstance = ChunkHandlerFactory::createChunkHandlerInstance();
-
- // Set handler instance
- $assemblerInstance->setHandlerInstance($handlerInstance);
-
- // Get stacker instance
- $stackInstance = ObjectFactory::createObjectByConfiguredName('multiple_message_stacker_class');
-
- // Initialize the only one stack
- $stackInstance->initStack(self::STACKER_NAME_MULTIPLE_MESSAGE);
-
- // And add it
- $assemblerInstance->setStackInstance($stackInstance);
-
- // Return the prepared instance
- return $assemblerInstance;
- }
-
- /**
- * Checks whether the input buffer (stacker to be more preceise) is empty.
- *
- * @return $isInputBufferEmpty Whether the input buffer is empty
- */
- private function ifInputBufferIsEmpty () {
- // Check it
- $isInputBufferEmpty = $this->getPackageInstance()->getStackInstance()->isStackEmpty(NetworkPackage::STACKER_NAME_DECODED_HANDLED);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: isInputBufferEmpty=' . intval($isInputBufferEmpty));
-
- // Return it
- return $isInputBufferEmpty;
- }
-
- /**
- * Checks whether given package content is completed (start/end markers are found)
- *
- * @param $packageContent An array with two elements: 'raw_data' and 'error_code'
- * @return $isCompleted Whether the given package content is completed
- */
- private function isPackageContentCompleted (array $packageContent) {
- // Check both
- $isCompleted = $this->ifStartEndMarkersSet($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]);
-
- // Return status
- return $isCompleted;
- }
-
- /**
- * Assembles the content from $packageContent. This method does only
- * initialize the whole process by creating a call-back which will then
- * itself (99.9% of all cases) "explode" the decoded data stream and add
- * it to a chunk assembler queue.
- *
- * If the call-back method or this would attempt to assemble the package
- * chunks and (maybe) re-request some chunks from the sender, this would
- * take to much time and therefore slow down this node again.
- *
- * @param $packageContent An array with two elements: 'raw_data' and 'error_code'
- * @return void
- * @throws UnsupportedPackageCodeHandlerException If the package code handler is not implemented
- */
- public function chunkPackageContent (array $packageContent) {
- // Validate the package content array again
- assert(
- (isset($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA])) &&
- (isset($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]))
- );
-
- // Construct call-back name from package error code
- $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]] = 'handlePackageBy' . self::convertToClassName($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]);
-
- // Abort if the call-back method is not there
- if (!method_exists($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]])) {
- // Throw an exception
- throw new UnsupportedPackageCodeHandlerException(array($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]], $packageContent), BaseListener::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER);
- } // END - if
-
- // Call it back
- call_user_func(array($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]]), $packageContent);
- }
-
- /**************************************************************************
- * Call-back methods for above method *
- **************************************************************************/
-
- /**
- * Call-back handler to handle unhandled package data. This method
- * "explodes" the string with the chunk separator from PackageFragmenter
- * class, does some low checks on it and feeds it into another queue for
- * verification and re-request for bad chunks.
- *
- * @param $packageContent An array with two elements: 'raw_data' and 'error_code'
- * @return void
- */
- private function handlePackageByUnhandledPackage (array $packageContent) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: packageData[' . BaseRawDataHandler::PACKAGE_RAW_DATA . ']=' . $packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]);
-
- // Check for some conditions
- if ((!$this->ifInputBufferIsEmpty()) || (!$this->isPackageContentCompleted($packageContent))) {
- // Last chunk is not valid, so wait for more
- $this->pendingData .= $packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA];
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Partial data received. Waiting for more ... ( ' . strlen($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]) . ' bytes)');
- } else {
- // Debug message
- //* DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ': packageContent=' . print_r($packageContent, TRUE) . ',chunks='.print_r($chunks, TRUE));
- }
- }
-
- /**
- * Checks whether the assembler's pending data is empty which means it has
- * no pending data left for handling ... ;-)
- *
- * @return $ifPendingDataIsEmpty Whether pending data is empty
- */
- public function isPendingDataEmpty () {
- // A simbple check
- $ifPendingDataIsEmpty = empty($this->pendingData);
-
- // Return it
- return $ifPendingDataIsEmpty;
- }
-
- /**
- * Checks whether the assembler has multiple messages pending
- *
- * @return $isPending Whether the assembler has multiple messages pending
- */
- public function ifMultipleMessagesPending () {
- // Determine it
- $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_MULTIPLE_MESSAGE));
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ': isPending=' . intval($isPending));
- return $isPending;
- }
-
- /**
- * Handles the assembler's pending data
- *
- * @return void
- */
- public function handlePendingData () {
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to decode ' . strlen($this->pendingData) . ' Bytes of pending data. pendingData=' . $this->pendingData);
-
- // Assert on condition
- assert(!$this->isPendingDataEmpty());
-
- // No markers set?
- if (!$this->ifStartEndMarkersSet($this->pendingData)) {
- // This will cause an assertition in next call, so simply wait for more data
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Pending data of ' . strlen($this->pendingData) . ' Bytes are incomplete, waiting for more ...');
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: this->pendingData=' . $this->pendingData);
- return;
- } elseif (substr_count($this->pendingData, BaseRawDataHandler::STREAM_START_MARKER) > 1) {
- /*
- * Multiple messages found, so split off first message as the input
- * stream can only handle one message per time.
- */
- foreach (explode(BaseRawDataHandler::STREAM_START_MARKER, $this->pendingData) as $message) {
- // Prepend start marker again as it is needed to decode the message.
- $message = BaseRawDataHandler::STREAM_START_MARKER . $message;
-
- // Push it on stack
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_MULTIPLE_MESSAGE, $message);
- } // END - foreach
-
- // Clear pending data
- $this->clearPendingData();
-
- // ... and exit here
- return;
- }
-
- // Init fake array
- $packageContent = array(
- BaseRawDataHandler::PACKAGE_RAW_DATA => $this->getInputStreamInstance()->streamData($this->pendingData),
- BaseRawDataHandler::PACKAGE_ERROR_CODE => BaseRawDataHandler::SOCKET_ERROR_UNHANDLED
- );
-
- /*
- * Clear pending data as it has been processed and will be handled some
- * lines below.
- */
- $this->clearPendingData();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Last block of partial data received. A total of ' . strlen($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]) . ' bytes has been received.');
-
- // Make sure last CHUNK_SEPARATOR is not there
- if (substr($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA], -1, 1) == PackageFragmenter::CHUNK_SEPARATOR) {
- // Remove it
- $packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA] = substr($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA], 0, -1);
- } // END - if
-
- /*
- * "explode" the string from 'raw_data' with chunk separator to get an
- * array of chunks. These chunks must then be verified by their
- * checksums. Also the final chunk must be handled.
- */
- $chunks = explode(PackageFragmenter::CHUNK_SEPARATOR, $packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]);
-
- // Add all chunks because the last final chunk is found
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-ASSEMBLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to add ' . count($chunks) . ' to chunk handler ...');
- $this->getHandlerInstance()->addAllChunksWithFinal($chunks);
- }
-
- /**
- * Handles multiple messages.
- *
- * @return void
- */
- public function handleMultipleMessages () {
- // Assert on condition
- assert($this->ifMultipleMessagesPending());
- assert($this->isPendingDataEmpty());
-
- // "Pop" next entry from stack and set it as new pending data
- $this->pendingData = $this->getStackInstance()->popNamed(self::STACKER_NAME_MULTIPLE_MESSAGE);
-
- // And handle it
- $this->handlePendingData();
- }
-
- /**
- * Accepts the visitor to process the visit "request"
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit the assembler
- $visitorInstance->visitAssembler($this);
- }
-
- /**
- * Clears pending data
- *
- * @return void
- */
- public function clearPendingData () {
- // Clear it
- $this->pendingData = '';
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A NetworkPackage class. This class implements Deliverable and Receivable
- * because all network packages should be deliverable to other nodes and
- * receivable from other nodes. It further provides methods for reading raw
- * content from template engines and feeding it to the stacker for undeclared
- * packages.
- *
- * The factory method requires you to provide a compressor class (which must
- * implement the Compressor interface). If you don't want any compression (not
- * adviceable due to increased network load), please use the NullCompressor
- * class and encode it with BASE64 for a more error-free transfer over the
- * Internet.
- *
- * For performance reasons, this class should only be instanciated once and then
- * used as a "pipe-through" class.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Needs to add functionality for handling the object's type
- *
- * 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 NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, Registerable, Visitable {
- /**
- * Package mask for compressing package data:
- * 0: Compressor extension
- * 1: Raw package data
- * 2: Tags, seperated by semicolons, no semicolon is required if only one tag is needed
- * 3: Checksum
- * 0 1 2 3
- */
- const PACKAGE_MASK = '%s%s%s%s%s%s%s';
-
- /**
- * Separator for the above mask
- */
- const PACKAGE_MASK_SEPARATOR = '^';
-
- /**
- * Size of an array created by invoking
- * explode(NetworkPackage::PACKAGE_MASK_SEPARATOR, $content).
- */
- const PACKAGE_CONTENT_ARRAY_SIZE = 4;
-
- /**
- * Separator for checksum
- */
- const PACKAGE_CHECKSUM_SEPARATOR = '_';
-
- /**
- * Array indexes for above mask, start with zero
- */
- const INDEX_COMPRESSOR_EXTENSION = 0;
- const INDEX_PACKAGE_DATA = 1;
- const INDEX_TAGS = 2;
- const INDEX_CHECKSUM = 3;
-
- /**
- * Array indexes for raw package array
- */
- const INDEX_PACKAGE_SENDER = 0;
- const INDEX_PACKAGE_RECIPIENT = 1;
- const INDEX_PACKAGE_CONTENT = 2;
- const INDEX_PACKAGE_STATUS = 3;
- const INDEX_PACKAGE_HASH = 4;
- const INDEX_PACKAGE_PRIVATE_KEY_HASH = 5;
-
- /**
- * Size of the decoded data array
- */
- const DECODED_DATA_ARRAY_SIZE = 6;
-
- /**
- * Named array elements for decoded package content
- */
- const PACKAGE_CONTENT_EXTENSION = 'compressor';
- const PACKAGE_CONTENT_MESSAGE = 'message';
- const PACKAGE_CONTENT_TAGS = 'tags';
- const PACKAGE_CONTENT_CHECKSUM = 'checksum';
- const PACKAGE_CONTENT_SENDER = 'sender';
- const PACKAGE_CONTENT_HASH = 'hash';
- const PACKAGE_CONTENT_PRIVATE_KEY_HASH = 'pkhash';
-
- /**
- * Named array elements for package data
- */
- const PACKAGE_DATA_SENDER = 'sender';
- const PACKAGE_DATA_RECIPIENT = 'recipient';
- const PACKAGE_DATA_CONTENT = 'content';
- const PACKAGE_DATA_STATUS = 'status';
- const PACKAGE_DATA_HASH = 'hash';
- const PACKAGE_DATA_PRIVATE_KEY_HASH = 'pkhash';
-
- /**
- * All package status
- */
- const PACKAGE_STATUS_NEW = 'new';
- const PACKAGE_STATUS_FAILED = 'failed';
- const PACKAGE_STATUS_DECODED = 'decoded';
- const PACKAGE_STATUS_FAKED = 'faked';
-
- /**
- * Constants for message data array
- */
- const MESSAGE_ARRAY_DATA = 'message_data';
- const MESSAGE_ARRAY_TYPE = 'message_type';
- const MESSAGE_ARRAY_SENDER = 'message_sender';
- const MESSAGE_ARRAY_HASH = 'message_hash';
- const MESSAGE_ARRAY_TAGS = 'message_tags';
-
- /**
- * Generic answer status field
- */
-
- /**
- * Tags separator
- */
- const PACKAGE_TAGS_SEPARATOR = ';';
-
- /**
- * Raw package data separator
- */
- const PACKAGE_DATA_SEPARATOR = '#';
-
- /**
- * Separator for more than one recipient
- */
- const PACKAGE_RECIPIENT_SEPARATOR = ':';
-
- /**
- * Network target (alias): 'upper nodes'
- */
- const NETWORK_TARGET_UPPER = 'upper';
-
- /**
- * Network target (alias): 'self'
- */
- const NETWORK_TARGET_SELF = 'self';
-
- /**
- * Network target (alias): 'dht'
- */
- const NETWORK_TARGET_DHT = 'dht';
-
- /**
- * TCP package size in bytes
- */
- const TCP_PACKAGE_SIZE = 512;
-
- /**************************************************************************
- * Stacker for out-going packages *
- **************************************************************************/
-
- /**
- * Stacker name for "undeclared" packages
- */
- const STACKER_NAME_UNDECLARED = 'package_undeclared';
-
- /**
- * Stacker name for "declared" packages (which are ready to send out)
- */
- const STACKER_NAME_DECLARED = 'package_declared';
-
- /**
- * Stacker name for "out-going" packages
- */
- const STACKER_NAME_OUTGOING = 'package_outgoing';
-
- /**************************************************************************
- * Stacker for incoming packages *
- **************************************************************************/
-
- /**
- * Stacker name for "incoming" decoded raw data
- */
- const STACKER_NAME_DECODED_INCOMING = 'package_decoded_data';
-
- /**
- * Stacker name for handled decoded raw data
- */
- const STACKER_NAME_DECODED_HANDLED = 'package_handled_decoded';
-
- /**
- * Stacker name for "chunked" decoded raw data
- */
- const STACKER_NAME_DECODED_CHUNKED = 'package_chunked_decoded';
-
- /**************************************************************************
- * Stacker for incoming messages *
- **************************************************************************/
-
- /**
- * Stacker name for new messages
- */
- const STACKER_NAME_NEW_MESSAGE = 'package_new_message';
-
- /**
- * Stacker name for processed messages
- */
- const STACKER_NAME_PROCESSED_MESSAGE = 'package_processed_message';
-
- /**************************************************************************
- * Stacker for raw data handling *
- **************************************************************************/
-
- /**
- * Stacker for outgoing data stream
- */
- 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 *
- **************************************************************************/
- const PROTOCOL_TCP = 'TCP';
- const PROTOCOL_UDP = 'UDP';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $compressorInstance A Compressor instance for compressing the content
- * @return $packageInstance An instance of a Deliverable class
- */
- public static final function createNetworkPackage (Compressor $compressorInstance) {
- // Get new instance
- $packageInstance = new NetworkPackage();
-
- // Now set the compressor instance
- $packageInstance->setCompressorInstance($compressorInstance);
-
- /*
- * We need to initialize a stack here for our packages even for those
- * which have no recipient address and stamp... ;-) This stacker will
- * also be used for incoming raw data to handle it.
- */
- $stackInstance = ObjectFactory::createObjectByConfiguredName('network_package_stacker_class');
-
- // At last, set it in this class
- $packageInstance->setStackInstance($stackInstance);
-
- // Init all stacker
- $packageInstance->initStacks();
-
- // Get a visitor instance for speeding up things and set it
- $visitorInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_monitor_visitor_class');
- $packageInstance->setVisitorInstance($visitorInstance);
-
- // Get crypto instance and set it, too
- $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
- $packageInstance->setCryptoInstance($cryptoInstance);
-
- // Get a singleton package assembler instance from factory and set it here, too
- $assemblerInstance = PackageAssemblerFactory::createAssemblerInstance($packageInstance);
- $packageInstance->setAssemblerInstance($assemblerInstance);
-
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Get pool instance from node
- $poolInstance = $nodeInstance->getListenerPoolInstance();
-
- // And set it here
- $packageInstance->setListenerPoolInstance($poolInstance);
-
- // Return the prepared instance
- return $packageInstance;
- }
-
- /**
- * Initialize all stackers
- *
- * @param $forceReInit Whether to force reinitialization of all stacks
- * @return void
- */
- protected function initStacks ($forceReInit = FALSE) {
- // Initialize all
- $this->getStackInstance()->initStacks(array(
- self::STACKER_NAME_UNDECLARED,
- self::STACKER_NAME_DECLARED,
- self::STACKER_NAME_OUTGOING,
- self::STACKER_NAME_DECODED_INCOMING,
- self::STACKER_NAME_DECODED_HANDLED,
- self::STACKER_NAME_DECODED_CHUNKED,
- self::STACKER_NAME_NEW_MESSAGE,
- self::STACKER_NAME_PROCESSED_MESSAGE,
- self::STACKER_NAME_OUTGOING_STREAM
- ), $forceReInit);
- }
-
- /**
- * Determines private key hash from given session id
- *
- * @param $decodedData Array with decoded data
- * @return $hash Private key's hash
- */
- private function determineSenderPrivateKeyHash (array $decodedData) {
- // Get DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Ask DHT for session id
- $senderData = $dhtInstance->findNodeLocalBySessionId($decodedData[self::PACKAGE_CONTENT_SENDER]);
-
- // Is an entry found?
- if (count($senderData) > 0) {
- // Make sure the element 'private_key_hash' is there
- //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderData=' . print_r($senderData, TRUE));
- assert(isset($senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH]));
-
- // Return it
- return $senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH];
- } // END - if
-
- // Make sure the requested element is there
- //* DEBUG-DIE */ die('decodedData=' . print_r($decodedData, TRUE));
- assert(isset($decodedData[self::PACKAGE_CONTENT_PRIVATE_KEY_HASH]));
-
- // There is no DHT entry so, accept the hash from decoded data
- return $decodedData[self::PACKAGE_CONTENT_PRIVATE_KEY_HASH];
- }
-
- /**
- * "Getter" for hash from given content
- *
- * @param $content Raw package content
- * @return $hash Hash for given package content
- */
- private function getHashFromContent ($content) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
-
- // Create the hash
- // @TODO md5() is very weak, but it needs to be fast
- $hash = md5(
- $content .
- self::PACKAGE_CHECKSUM_SEPARATOR .
- $this->getSessionId() .
- self::PACKAGE_CHECKSUM_SEPARATOR .
- $this->getCompressorInstance()->getCompressorExtension()
- );
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
-
- // And return it
- return $hash;
- }
-
- /**
- * Checks whether the checksum (sometimes called "hash") is the same
- *
- * @param $decodedContent Package raw content
- * @param $decodedData Whole raw package data array
- * @return $isChecksumValid Whether the checksum is the same
- */
- private function isChecksumValid (array $decodedContent, array $decodedData) {
- // Get checksum
- $checksum = $this->getHashFromContentSessionId($decodedContent, $decodedData[self::PACKAGE_DATA_SENDER]);
-
- // Is it the same?
- $isChecksumValid = ($checksum == $decodedContent[self::PACKAGE_CONTENT_CHECKSUM]);
-
- // Return it
- return $isChecksumValid;
- }
-
- /**
- * Change the package with given status in given stack
- *
- * @param $packageData Raw package data in an array
- * @param $stackerName Name of the stacker
- * @param $newStatus New status to set
- * @return void
- */
- private function changePackageStatus (array $packageData, $stackerName, $newStatus) {
- // Skip this for empty stacks
- if ($this->getStackInstance()->isStackEmpty($stackerName)) {
- // This avoids an exception after all packages has failed
- return;
- } // END - if
-
- // Pop the entry (it should be it)
- $nextData = $this->getStackInstance()->popNamed($stackerName);
-
- // Compare both hashes
- assert($nextData[self::PACKAGE_DATA_HASH] == $packageData[self::PACKAGE_DATA_HASH]);
-
- // Temporary set the new status
- $packageData[self::PACKAGE_DATA_STATUS] = $newStatus;
-
- // And push it again
- $this->getStackInstance()->pushNamed($stackerName, $packageData);
- }
-
- /**
- * "Getter" for hash from given content and sender's session id
- *
- * @param $decodedContent Raw package content
- * @param $sessionId Session id of the sender
- * @return $hash Hash for given package content
- */
- public function getHashFromContentSessionId (array $decodedContent, $sessionId) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_EXTENSION]);
-
- // Create the hash
- // @TODO md5() is very weak, but it needs to be fast
- $hash = md5(
- $decodedContent[self::PACKAGE_CONTENT_MESSAGE] .
- self::PACKAGE_CHECKSUM_SEPARATOR .
- $sessionId .
- self::PACKAGE_CHECKSUM_SEPARATOR .
- $decodedContent[self::PACKAGE_CONTENT_EXTENSION]
- );
-
- // And return it
- return $hash;
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Delivering packages / raw data
- ///////////////////////////////////////////////////////////////////////////
-
- /**
- * Declares the given raw package data by discovering recipients
- *
- * @param $packageData Raw package data in an array
- * @return void
- */
- private function declareRawPackageData (array $packageData) {
- // Make sure the required field is there
- assert(isset($packageData[self::PACKAGE_DATA_RECIPIENT]));
-
- /*
- * We need to disover every recipient, just in case we have a
- * multi-recipient entry like 'upper' is. 'all' may be a not so good
- * target because it causes an overload on the network and may be
- * abused for attacking the network with large packages.
- */
- $discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
-
- // Discover all recipients, this may throw an exception
- $discoveryInstance->discoverRecipients($packageData);
-
- // Now get an iterator
- $iteratorInstance = $discoveryInstance->getIterator();
-
- // Make sure the iterator instance is valid
- assert($iteratorInstance instanceof Iterator);
-
- // Rewind back to the beginning
- $iteratorInstance->rewind();
-
- // ... and begin iteration
- while ($iteratorInstance->valid()) {
- // Get current entry
- $currentRecipient = $iteratorInstance->current();
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]);
-
- // Set the recipient
- $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient;
-
- // Push the declared package to the next stack.
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData);
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package declared for recipient ' . $currentRecipient);
-
- // Skip to next entry
- $iteratorInstance->next();
- } // END - while
-
- /*
- * The recipient list can be cleaned up here because the package which
- * shall be delivered has already been added for all entries from the
- * list.
- */
- $discoveryInstance->clearRecipients();
- }
-
- /**
- * Delivers raw package data. In short, this will discover the raw socket
- * resource through a discovery class (which will analyse the receipient of
- * the package), register the socket with the connection (handler/helper?)
- * instance and finally push the raw data on our outgoing queue.
- *
- * @param $packageData Raw package data in an array
- * @return void
- */
- private function deliverRawPackageData (array $packageData) {
- /*
- * This package may become big, depending on the shared object size or
- * delivered message size which shouldn't be so long (to save
- * bandwidth). Because of the nature of the used protocol (TCP) we need
- * to split it up into smaller pieces to fit it into a TCP frame.
- *
- * So first we need (again) a discovery class but now a protocol
- * discovery to choose the right socket resource. The discovery class
- * should take a look at the raw package data itself and then decide
- * which (configurable!) protocol should be used for that type of
- * package.
- */
- $discoveryInstance = SocketDiscoveryFactory::createSocketDiscoveryInstance();
-
- // Now discover the right protocol
- $socketResource = $discoveryInstance->discoverSocket($packageData, BaseConnectionHelper::CONNECTION_TYPE_OUTGOING);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' after discoverSocket() has been called.');
-
- // Debug message
- //* 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.');
-
- // 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');
-
- // And make sure it is valid
- assert($helperInstance instanceof ConnectionHelper);
-
- // Get connection info class
- $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($helperInstance->getProtocolName(), 'helper');
-
- // Will the info instance with connection helper data
- $infoInstance->fillWithConnectionHelperInformation($helperInstance);
-
- // Is it not there?
- if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($infoInstance, $socketResource))) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Registering socket ' . $socketResource . ' ...');
-
- // Then register it
- $registryInstance->registerSocket($infoInstance, $socketResource, $packageData);
- } elseif (!$helperInstance->getStateInstance()->isPeerStateConnected()) {
- // Is not connected, then we cannot send
- self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.');
-
- // Shutdown the socket
- $this->shutdownSocket($socketResource);
- }
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.');
-
- // Make sure the connection is up
- $helperInstance->getStateInstance()->validatePeerStateConnected();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.');
-
- // Enqueue it again on the out-going queue, the connection is up and working at this point
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageData);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' after pushNamed() has been called.');
- }
-
- /**
- * Sends waiting packages
- *
- * @param $packageData Raw package data
- * @return void
- */
- private function sendOutgoingRawPackageData (array $packageData) {
- // Init sent bytes
- $sentBytes = 0;
-
- // Get the right connection instance
- $infoInstance = SocketRegistryFactory::createSocketRegistryInstance()->getInfoInstanceFromPackageData($packageData);
-
- // Test helper instance
- assert($infoInstance instanceof ShareableInfo);
-
- // Get helper instance
- $helperInstance = $infoInstance->getHelperInstance();
-
- // Some sanity-checks on the object
- //* DEBUG-DIE: */ die('[' . __METHOD__ . ':' . __LINE__ . ']: p1=' . $infoInstance->getProtocolName() . ',p2=' . $helperInstance->getProtocolName() . ',infoInstance=' . print_r($infoInstance, TRUE));
- assert($helperInstance instanceof ConnectionHelper);
- assert($infoInstance->getProtocolName() == $helperInstance->getProtocolName());
-
- // Is this connection still alive?
- if ($helperInstance->isShuttedDown()) {
- // This connection is shutting down
- // @TODO We may want to do somthing more here?
- return;
- } // END - if
-
- // Sent out package data
- $helperInstance->sendRawPackageData($packageData);
- }
-
- /**
- * Generates a secure hash for given raw package content and sender id
- *
- * @param $content Raw package data
- * @param $senderId Sender id to generate a hash for
- * @return $hash Hash as hex-encoded string
- */
- private function generatePackageHash ($content, $senderId) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: content()=' . strlen($content) . ',senderId=' . $senderId . ' - CALLED!');
-
- // Is the feature enabled?
- if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
- // Feature is not enabled
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Feature "hubcoin_reward" not available, not generating package hash. Returning NULL ...');
- return NULL;
- } // END - if
-
- // Fake array
- $data = array(
- self::PACKAGE_CONTENT_SENDER => $senderId,
- self::PACKAGE_CONTENT_MESSAGE => $content,
- self::PACKAGE_CONTENT_PRIVATE_KEY_HASH => ''
- );
-
- // Hash content and sender id together, use scrypt
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $senderId . ',content()=' . strlen($content));
- $hash = FrameworkFeature::callFeature('hubcoin_reward', 'generateHash', array($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($data)));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash . ' - EXIT!');
-
- // Return it
- return $hash;
- }
-
- /**
- * Checks whether the hash of given package data is 'valid', here that
- * means it is the same or not.
- *
- * @param $decodedArray An array with 'decoded' (explode() was mostly called) data
- * @return $isHashValid Whether the hash is valid
- * @todo Unfinished area, hashes are currently NOT fully supported
- */
- private function isPackageHashValid (array $decodedArray) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: decodedArray=' . print_r($decodedArray, TRUE) . ' - CALLED!');
-
- // Make sure the required array elements are there
- assert(isset($decodedArray[self::PACKAGE_CONTENT_SENDER]));
- assert(isset($decodedArray[self::PACKAGE_CONTENT_MESSAGE]));
- assert(isset($decodedArray[self::PACKAGE_CONTENT_HASH]));
-
- // Is the feature enabled?
- if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
- // Feature is not enabled, so hashes are always valid
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Feature "hubcoin_reward" not available, not checking hash. Returning TRUE ...');
- return TRUE;
- } // END - if
-
- // Check validity
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $decodedArray[self::PACKAGE_CONTENT_SENDER] . ',message()=' . strlen($decodedArray[self::PACKAGE_CONTENT_MESSAGE]) . '),hash=' . $decodedArray[self::PACKAGE_CONTENT_HASH]);
- //* DEBUG-DIE: */ die(__METHOD__ . ': decodedArray=' . print_r($decodedArray, TRUE));
- $isHashValid = FrameworkFeature::callFeature('hubcoin_reward', 'checkHash', array($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_MESSAGE] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH]));
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: isHashValid=' . intval($isHashValid) . ' - EXIT!');
- return $isHashValid;
- }
-
- /**
- * "Enqueues" raw content into this delivery class by reading the raw content
- * from given helper's template instance and pushing it on the 'undeclared'
- * stack.
- *
- * @param $helperInstance An instance of a HubHelper class
- * @return void
- */
- public function enqueueRawDataFromTemplate (HubHelper $helperInstance) {
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
-
- // Get the raw content ...
- $content = $helperInstance->getTemplateInstance()->getRawTemplateData();
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('content(' . strlen($content) . ')=' . $content);
-
- // ... and compress it
- $compressed = $this->getCompressorInstance()->compressStream($content);
-
- // Add magic in front of it and hash behind it, including BASE64 encoding
- $packageContent = sprintf(self::PACKAGE_MASK,
- // 1.) Compressor's extension
- $this->getCompressorInstance()->getCompressorExtension(),
- // - separator
- self::PACKAGE_MASK_SEPARATOR,
- // 2.) Compressed raw package content, encoded with BASE64
- base64_encode($compressed),
- // - separator
- self::PACKAGE_MASK_SEPARATOR,
- // 3.) Tags
- implode(self::PACKAGE_TAGS_SEPARATOR, $helperInstance->getPackageTags()),
- // - separator
- self::PACKAGE_MASK_SEPARATOR,
- // 4.) Checksum
- $this->getHashFromContent($compressed)
- );
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': Enqueueing package for recipientType=' . $helperInstance->getRecipientType() . ' ...');
-
- // Now prepare the temporary array and push it on the 'undeclared' stack
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array(
- self::PACKAGE_DATA_SENDER => $this->getSessionId(),
- self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(),
- self::PACKAGE_DATA_CONTENT => $packageContent,
- self::PACKAGE_DATA_STATUS => self::PACKAGE_STATUS_NEW,
- self::PACKAGE_DATA_HASH => $this->generatePackageHash($content, $this->getSessionId()),
- self::PACKAGE_DATA_PRIVATE_KEY_HASH => $this->getPrivateKeyHash(),
- ));
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
- }
-
- /**
- * Checks whether a package has been enqueued for delivery.
- *
- * @return $isEnqueued Whether a package is enqueued
- */
- public function isPackageEnqueued () {
- // Check whether the stacker is not empty
- $isEnqueued = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_UNDECLARED)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_UNDECLARED)));
-
- // Return the result
- return $isEnqueued;
- }
-
- /**
- * Checks whether a package has been declared
- *
- * @return $isDeclared Whether a package is declared
- */
- public function isPackageDeclared () {
- // Check whether the stacker is not empty
- $isDeclared = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_DECLARED)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECLARED)));
-
- // Return the result
- return $isDeclared;
- }
-
- /**
- * Checks whether a package should be sent out
- *
- * @return $isWaitingDelivery Whether a package is waiting for delivery
- */
- public function isPackageWaitingForDelivery () {
- // Check whether the stacker is not empty
- $isWaitingDelivery = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_OUTGOING)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_OUTGOING)));
-
- // Return the result
- 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->getStackInstance()->isStackInitialized(self::STACKER_NAME_OUTGOING_STREAM)) && (!$this->getStackInstance()->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).
- * This allows that a single package is being delivered to multiple targets
- * without enqueueing it for every target. If no target is provided or it
- * can't be determined a NoTargetException is being thrown.
- *
- * @return void
- * @throws NoTargetException If no target can't be determined
- */
- public function declareEnqueuedPackage () {
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
-
- // Make sure this method isn't working if there is no package enqueued
- if (!$this->isPackageEnqueued()) {
- // This is not fatal but should be avoided
- self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: No raw package data waiting declaration, but ' . __METHOD__ . ' has been called!');
- return;
- } // END - if
-
- /*
- * Now there are for sure packages to deliver, so start with the first
- * one.
- */
- $packageData = $this->getStackInstance()->popNamed(self::STACKER_NAME_UNDECLARED);
-
- // Declare the raw package data for delivery
- $this->declareRawPackageData($packageData);
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
- }
-
- /**
- * Delivers the next declared package. Only one package per time will be sent
- * because this may take time and slows down the whole delivery
- * infrastructure.
- *
- * @return void
- */
- public function processDeclaredPackage () {
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
-
- // Sanity check if we have packages declared
- if (!$this->isPackageDeclared()) {
- // This is not fatal but should be avoided
- self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: No package has been declared, but ' . __METHOD__ . ' has been called!');
- return;
- } // END - if
-
- // Get the package
- $packageData = $this->getStackInstance()->getNamed(self::STACKER_NAME_DECLARED);
-
- // Assert on it
- assert(isset($packageData[self::PACKAGE_DATA_RECIPIENT]));
-
- // Try to deliver the package
- try {
- // And try to send it
- $this->deliverRawPackageData($packageData);
-
- // And remove it finally
- $this->getStackInstance()->popNamed(self::STACKER_NAME_DECLARED);
- } catch (UnexpectedStateException $e) {
- // The state is not excepected (shall be 'connected')
- self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Caught ' . $e->__toString() . ',message=' . $e->getMessage());
-
- // Mark the package with status failed
- $this->changePackageStatus($packageData, self::STACKER_NAME_DECLARED, self::PACKAGE_STATUS_FAILED);
- }
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
- }
-
- /**
- * Sends waiting packages out for delivery
- *
- * @return void
- */
- public function sendWaitingPackage () {
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
-
- // Sanity check if we have packages waiting for delivery
- if (!$this->isPackageWaitingForDelivery()) {
- // This is not fatal but should be avoided
- self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: No package is waiting for delivery, but ' . __METHOD__ . ' was called.');
- return;
- } // END - if
-
- // Get the package
- $packageData = $this->getStackInstance()->getNamed(self::STACKER_NAME_OUTGOING);
-
- try {
- // Now try to send it
- $this->sendOutgoingRawPackageData($packageData);
-
- // And remove it finally
- $this->getStackInstance()->popNamed(self::STACKER_NAME_OUTGOING);
- } catch (InvalidSocketException $e) {
- // Output exception message
- self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package was not delivered: ' . $e->getMessage());
-
- // Mark package as failed
- $this->changePackageStatus($packageData, self::STACKER_NAME_OUTGOING, self::PACKAGE_STATUS_FAILED);
- }
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
- }
-
- /**
- * Sends out encoded data to a socket
- *
- * @return void
- */
- public function sendEncodedData () {
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
-
- // Make sure there is pending encoded data
- assert($this->isEncodedDataPending());
-
- // Pop current data from stack
- $encodedDataArray = $this->getStackInstance()->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->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Receiving packages / raw data
- ///////////////////////////////////////////////////////////////////////////
-
- /**
- * Checks whether decoded raw data is pending
- *
- * @return $isPending Whether decoded raw data is pending
- */
- private function isRawDataPending () {
- // Just return whether the stack is not empty
- $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_INCOMING));
-
- // Return the status
- return $isPending;
- }
-
- /**
- * Checks whether new raw package data has arrived at a socket
- *
- * @return $hasArrived Whether new raw package data has arrived for processing
- */
- public function isNewRawDataPending () {
- // Visit the pool. This monitors the pool for incoming raw data.
- $this->getListenerPoolInstance()->accept($this->getVisitorInstance());
-
- // Check for new data arrival
- $hasArrived = $this->isRawDataPending();
-
- // Return the status
- return $hasArrived;
- }
-
- /**
- * Handles the incoming decoded raw data. This method does not "convert" the
- * decoded data back into a package array, it just "handles" it and pushs it
- * on the next stack.
- *
- * @return void
- */
- public function handleIncomingDecodedData () {
- /*
- * This method should only be called if decoded raw data is pending,
- * so check it again.
- */
- if (!$this->isRawDataPending()) {
- // This is not fatal but should be avoided
- self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: No raw (decoded?) data is pending, but ' . __METHOD__ . ' has been called!');
- return;
- } // END - if
-
- // Very noisy debug message:
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Stacker size is ' . $this->getStackInstance()->getStackCount(self::STACKER_NAME_DECODED_INCOMING) . ' entries.');
-
- // "Pop" the next entry (the same array again) from the stack
- $decodedData = $this->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_INCOMING);
-
- // Make sure both array elements are there
- assert(
- (is_array($decodedData)) &&
- (isset($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA])) &&
- (isset($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE]))
- );
-
- /*
- * Also make sure the error code is SOCKET_ERROR_UNHANDLED because we
- * only want to handle unhandled packages here.
- */
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] . '(' . BaseRawDataHandler::SOCKET_ERROR_UNHANDLED . ')');
- assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == BaseRawDataHandler::SOCKET_ERROR_UNHANDLED);
-
- // Remove the last chunk SEPARATOR (because there is no need for it)
- if (substr($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA], -1, 1) == PackageFragmenter::CHUNK_SEPARATOR) {
- // It is there and should be removed
- $decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA] = substr($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA], 0, -1);
- } // END - if
-
- // This package is "handled" and can be pushed on the next stack
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Pushing ' . strlen($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA]) . ' bytes to stack ' . self::STACKER_NAME_DECODED_HANDLED . ' ...');
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_HANDLED, $decodedData);
- }
-
- /**
- * Adds raw decoded data from the given handler instance to this receiver
- *
- * @param $handlerInstance An instance of a Networkable class
- * @return void
- */
- public function addRawDataToIncomingStack (Networkable $handlerInstance) {
- /*
- * Get the decoded data from the handler, this is an array with
- * 'raw_data' and 'error_code' as elements.
- */
- $decodedData = $handlerInstance->getNextRawData();
-
- // Very noisy debug message:
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: decodedData[' . gettype($decodedData) . ']=' . print_r($decodedData, TRUE));
-
- // And push it on our stack
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_INCOMING, $decodedData);
- }
-
- /**
- * Checks whether incoming decoded data is handled.
- *
- * @return $isHandled Whether incoming decoded data is handled
- */
- public function isIncomingRawDataHandled () {
- // Determine if the stack is not empty
- $isHandled = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_HANDLED));
-
- // Return it
- return $isHandled;
- }
-
- /**
- * Checks whether the assembler has pending data left
- *
- * @return $isHandled Whether the assembler has pending data left
- */
- public function ifAssemblerHasPendingDataLeft () {
- // Determine if the stack is not empty
- $isHandled = (!$this->getAssemblerInstance()->isPendingDataEmpty());
-
- // Return it
- return $isHandled;
- }
-
- /**
- * Checks whether the assembler has multiple packages pending
- *
- * @return $isPending Whether the assembler has multiple packages pending
- */
- public function ifMultipleMessagesPending () {
- // Determine if the stack is not empty
- $isPending = ($this->getAssemblerInstance()->ifMultipleMessagesPending());
-
- // Return it
- return $isPending;
- }
-
- /**
- * Handles the attached assemler's pending data queue to be finally
- * assembled to the raw package data back.
- *
- * @return void
- */
- public function handleAssemblerPendingData () {
- // Handle it
- $this->getAssemblerInstance()->handlePendingData();
- }
-
- /**
- * Handles multiple messages.
- *
- * @return void
- */
- public function handleMultipleMessages () {
- // Handle it
- $this->getAssemblerInstance()->handleMultipleMessages();
- }
-
- /**
- * Assembles incoming decoded data so it will become an abstract network
- * package again. The assembler does later do it's job by an other task,
- * not this one to keep best speed possible.
- *
- * @return void
- */
- public function assembleDecodedDataToPackage () {
- // Make sure the raw decoded package data is handled
- assert($this->isIncomingRawDataHandled());
-
- // Get current package content (an array with two elements; see handleIncomingDecodedData() for details)
- $packageContent = $this->getStackInstance()->getNamed(self::STACKER_NAME_DECODED_HANDLED);
-
- // Assert on some elements
- assert(
- (is_array($packageContent)) &&
- (isset($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA])) &&
- (isset($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]))
- );
-
- // Start assembling the raw package data array by chunking it
- $this->getAssemblerInstance()->chunkPackageContent($packageContent);
-
- // Remove the package from 'handled_decoded' stack ...
- $this->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_HANDLED);
-
- // ... and push it on the 'chunked' stacker
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Pushing ' . strlen($packageContent[BaseRawDataHandler::PACKAGE_RAW_DATA]) . ' bytes on stack ' . self::STACKER_NAME_DECODED_CHUNKED . ',packageContent=' . print_r($packageContent, TRUE));
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_CHUNKED, $packageContent);
- }
-
- /**
- * Accepts the visitor to process the visit "request"
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - CALLED!');
-
- // Visit the package
- $visitorInstance->visitNetworkPackage($this);
-
- // Then visit the assembler to handle multiple packages
- $this->getAssemblerInstance()->accept($visitorInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - EXIT!');
- }
-
- /**
- * Clears all stacks
- *
- * @return void
- */
- public function clearAllStacks () {
- // Call the init method to force re-initialization
- $this->initStacks(TRUE);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: All stacker have been re-initialized.');
- }
-
- /**
- * Removes the first failed outoging package from the stack to continue
- * with next one (it will never work until the issue is fixed by you).
- *
- * @return void
- * @throws UnexpectedPackageStatusException If the package status is not 'failed'
- * @todo This may be enchanced for outgoing packages?
- */
- public function removeFirstFailedPackage () {
- // Get the package again
- $packageData = $this->getStackInstance()->getNamed(self::STACKER_NAME_DECLARED);
-
- // Is the package status 'failed'?
- if ($packageData[self::PACKAGE_DATA_STATUS] != self::PACKAGE_STATUS_FAILED) {
- // Not failed!
- throw new UnexpectedPackageStatusException(array($this, $packageData, self::PACKAGE_STATUS_FAILED), BaseListener::EXCEPTION_UNEXPECTED_PACKAGE_STATUS);
- } // END - if
-
- // Remove this entry
- $this->getStackInstance()->popNamed(self::STACKER_NAME_DECLARED);
- }
-
- /**
- * "Decode" the package content into the same array when it was sent.
- *
- * @param $rawPackageContent The raw package content to be "decoded"
- * @return $decodedData An array with 'sender', 'recipient', 'content' and 'status' elements
- */
- public function decodeRawContent ($rawPackageContent) {
- // Use the separator '#' to "decode" it
- $decodedArray = explode(self::PACKAGE_DATA_SEPARATOR, $rawPackageContent);
-
- // Assert on count (should be always 3)
- assert(count($decodedArray) == self::DECODED_DATA_ARRAY_SIZE);
-
- /*
- * Create 'decodedData' array with all assoziative array elements.
- */
- $decodedData = array(
- self::PACKAGE_DATA_SENDER => $decodedArray[self::INDEX_PACKAGE_SENDER],
- self::PACKAGE_DATA_RECIPIENT => $decodedArray[self::INDEX_PACKAGE_RECIPIENT],
- self::PACKAGE_DATA_CONTENT => $decodedArray[self::INDEX_PACKAGE_CONTENT],
- self::PACKAGE_DATA_STATUS => self::PACKAGE_STATUS_DECODED,
- self::PACKAGE_DATA_HASH => $decodedArray[self::INDEX_PACKAGE_HASH],
- self::PACKAGE_DATA_PRIVATE_KEY_HASH => $decodedArray[self::INDEX_PACKAGE_PRIVATE_KEY_HASH]
- );
-
- // And return it
- return $decodedData;
- }
-
- /**
- * Handles decoded data for this node by "decoding" the 'content' part of
- * it. Again this method uses explode() for the "decoding" process.
- *
- * @param $decodedData An array with decoded raw package data
- * @return void
- * @throws InvalidDataChecksumException If the checksum doesn't match
- */
- public function handleRawData (array $decodedData) {
- /*
- * "Decode" the package's content by a simple explode() call, for
- * details of the array elements, see comments for constant
- * PACKAGE_MASK.
- */
- $decodedContent = explode(self::PACKAGE_MASK_SEPARATOR, $decodedData[self::PACKAGE_DATA_CONTENT]);
-
- // Assert on array count for a very basic validation
- assert(count($decodedContent) == self::PACKAGE_CONTENT_ARRAY_SIZE);
-
- /*
- * Convert the indexed array into an associative array. This is much
- * better to remember than plain numbers, isn't it?
- */
- $decodedContent = array(
- // Compressor's extension used to compress the data
- self::PACKAGE_CONTENT_EXTENSION => $decodedContent[self::INDEX_COMPRESSOR_EXTENSION],
- // Package data (aka "message") in BASE64-decoded form but still compressed
- self::PACKAGE_CONTENT_MESSAGE => base64_decode($decodedContent[self::INDEX_PACKAGE_DATA]),
- // Tags as an indexed array for "tagging" the message
- self::PACKAGE_CONTENT_TAGS => explode(self::PACKAGE_TAGS_SEPARATOR, $decodedContent[self::INDEX_TAGS]),
- // Checksum of the _decoded_ data
- self::PACKAGE_CONTENT_CHECKSUM => $decodedContent[self::INDEX_CHECKSUM],
- // Sender's id
- self::PACKAGE_CONTENT_SENDER => $decodedData[self::PACKAGE_DATA_SENDER],
- // Hash from decoded raw data
- self::PACKAGE_CONTENT_HASH => $decodedData[self::PACKAGE_DATA_HASH],
- // Hash of private key
- self::PACKAGE_CONTENT_PRIVATE_KEY_HASH => $decodedData[self::PACKAGE_DATA_PRIVATE_KEY_HASH]
- );
-
- // Is the checksum valid?
- if (!$this->isChecksumValid($decodedContent, $decodedData)) {
- // Is not the same, so throw an exception here
- throw new InvalidDataChecksumException(array($this, $decodedContent, $decodedData), BaseListener::EXCEPTION_INVALID_DATA_CHECKSUM);
- } // END - if
-
- /*
- * The checksum is the same, then it can be decompressed safely. The
- * original message is at this point fully decoded.
- */
- $decodedContent[self::PACKAGE_CONTENT_MESSAGE] = $this->getCompressorInstance()->decompressStream($decodedContent[self::PACKAGE_CONTENT_MESSAGE]);
-
- // And push it on the next stack
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_NEW_MESSAGE, $decodedContent);
- }
-
- /**
- * Checks whether a new message has arrived
- *
- * @return $hasArrived Whether a new message has arrived for processing
- */
- public function isNewMessageArrived () {
- // Determine if the stack is not empty
- $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_NEW_MESSAGE));
-
- // Return it
- return $hasArrived;
- }
-
- /**
- * Handles newly arrived messages
- *
- * @return void
- * @todo Implement verification of all sent tags here?
- */
- public function handleNewlyArrivedMessage () {
- // Make sure there is at least one message
- assert($this->isNewMessageArrived());
-
- // Get it from the stacker, it is the full array with the decoded message
- $decodedContent = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
-
- // Generate the hash of comparing it
- if (!$this->isPackageHashValid($decodedContent)) {
- // Is not valid, so throw an exception here
- exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . chr(10));
- } // END - if
-
- // Now get a filter chain back from factory with given tags array
- $chainInstance = PackageFilterChainFactory::createChainByTagsArray($decodedContent[self::PACKAGE_CONTENT_TAGS]);
-
- /*
- * Process the message through all filters, note that all other
- * elements from $decodedContent are no longer needed.
- */
- $chainInstance->processMessage($decodedContent, $this);
-
- /*
- * Post-processing of message data (this won't remote the message from
- * the stack).
- */
- $chainInstance->postProcessMessage($this);
- }
-
- /**
- * Checks whether a processed message is pending for "interpretation"
- *
- * @return $isPending Whether a processed message is pending
- */
- public function isProcessedMessagePending () {
- // Check it
- $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PROCESSED_MESSAGE));
-
- // Return it
- return $isPending;
- }
-
- /**
- * Handle processed messages by "interpreting" the 'message_type' element
- *
- * @return void
- */
- public function handleProcessedMessage () {
- // Get it from the stacker, it is the full array with the processed message
- $messageArray = $this->getStackInstance()->popNamed(self::STACKER_NAME_PROCESSED_MESSAGE);
-
- // Add type for later easier handling
- $messageArray[self::MESSAGE_ARRAY_DATA][self::MESSAGE_ARRAY_TYPE] = $messageArray[self::MESSAGE_ARRAY_TYPE];
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: messageArray=' . print_r($messageArray, TRUE));
-
- // Create a handler instance from given message type
- $handlerInstance = MessageTypeHandlerFactory::createMessageTypeHandlerInstance($messageArray[self::MESSAGE_ARRAY_TYPE]);
-
- // Handle message data
- $handlerInstance->handleMessageData($messageArray[self::MESSAGE_ARRAY_DATA], $this);
-
- // Post-handling of message data
- $handlerInstance->postHandleMessageData($messageArray, $this);
- }
-
- /**
- * Feeds the hash and sender (as recipient for the 'sender' reward) to the
- * miner's queue, unless the message is not a "reward claim" message as this
- * leads to an endless loop. You may wish to run the miner to get some
- * reward ("Hubcoins") for "mining" this hash.
- *
- * @param $messageData Array with message data
- * @return void
- * @todo ~10% done?
- */
- public function feedHashToMiner (array $messageData) {
- // Is the feature enabled?
- if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
- /*
- * Feature is not enabled, don't feed the hash to the miner as it
- *may be invalid.
- */
- return;
- } // END - if
-
- // Make sure the required elements are there
- assert(isset($messageData[self::MESSAGE_ARRAY_SENDER]));
- assert(isset($messageData[self::MESSAGE_ARRAY_HASH]));
- assert(isset($messageData[self::MESSAGE_ARRAY_TAGS]));
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
-
- // Resolve session id ('sender' is a session id) into node id
- $nodeId = HubTools::resolveNodeIdBySessionId($messageData[self::MESSAGE_ARRAY_SENDER]);
-
- // Is 'claim_reward' the message type?
- if (in_array('claim_reward', $messageData[self::MESSAGE_ARRAY_TAGS])) {
- /*
- * Then don't feed this message to the miner as this causes an
- * endless loop of mining.
- */
- return;
- } // END - if
-
- $this->partialStub('@TODO nodeId=' . $nodeId . ',messageData=' . print_r($messageData, TRUE));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A PackageFragmenter class to fragment package data into smaller chunks for
- * delivery. This class calculates a final hash on the raw input data and
- * fragments the data into smaller chunks after it has been encoded by a
- * "outgoing encoding stream".
- *
- * All chunks are extended with a hash and a serial number to make it later
- * easier to verify them and put them back in the right order and to, if
- * required, request a re-delivery of an invalid chunk (e.g. hash didn't match).
- * Also an "end-of-package" marker is being added as the last chunk to mark the
- * end of of the whole package submission.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageFragmenter extends BaseHubSystem implements Fragmentable, Registerable {
- /**
- * Cached chunk size in bits
- */
- private $chunkSize = 0;
-
- /**
- * Array for chunks
- */
- private $chunks = array();
-
- /**
- * Array for chunk hashes
- */
- private $chunkHashes = array();
-
- /**
- * Array for chunk pointers
- */
- private $chunkPointers = array();
-
- /**
- * Array for processed packages
- */
- private $processedPackages = array();
-
- /**
- * Serial numbers (array key is final hash)
- */
- private $serialNumber = array();
-
- /**
- * Maximum possible serial number, "cache" for speeding up things
- */
- private $maxSerialNumber = 0;
-
- /**
- * Length of largest possible serial number
- */
- const MAX_SERIAL_LENGTH = 8;
-
- /**
- * Separator between chunk data, serial number and chunk hash
- */
- const CHUNK_DATA_HASH_SEPARATOR = '@';
-
- /**
- * SEPARATOR for all chunk hashes
- */
- const CHUNK_HASH_SEPARATOR = ';';
-
- /**
- * SEPARATOR between two chunks
- */
- const CHUNK_SEPARATOR = '|';
-
- /**
- * Identifier for hash chunk
- */
- const HASH_CHUNK_IDENTIFIER = 'HASH-CHUNK:';
-
- /**
- * Identifier for end-of-package marker
- */
- const END_OF_PACKAGE_IDENTIFIER = 'EOP:';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init this fragmenter
- $this->initFragmenter();
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $fragmenterInstance An instance of a Fragmentable class
- */
- public static final function createPackageFragmenter () {
- // Get new instance
- $fragmenterInstance = new PackageFragmenter();
-
- // Get a crypto instance and set it here
- $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
- $fragmenterInstance->setCryptoInstance($cryptoInstance);
-
- // Return the prepared instance
- return $fragmenterInstance;
- }
-
- /**
- * Initializes this fragmenter
- *
- * @return void
- */
- private function initFragmenter () {
- // Load some configuration entries and "cache" them:
- // - Chunk size in bits
- $this->chunkSize = $this->getConfigInstance()->getConfigEntry('package_chunk_size');
-
- // - Maximum serial number
- $this->maxSerialNumber = $this->hex2dec(str_repeat('f', self::MAX_SERIAL_LENGTH));
- }
-
- /**
- * Initializes the pointer for given final hash
- *
- * @param $finalHash Final hash to initialize pointer for
- * @return void
- */
- private function initPointer ($finalHash) {
- $this->chunkPointers[$finalHash] = 0;
- }
-
- /**
- * "Getter" for processedPackages array index
- *
- * @param $packageData Raw package data array
- * @return $index Array index for processedPackages
- */
- private function getProcessedPackagesIndex (array $packageData) {
- return (
- $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . NetworkPackage::PACKAGE_DATA_SEPARATOR .
- $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . NetworkPackage::PACKAGE_DATA_SEPARATOR .
- $packageData[NetworkPackage::PACKAGE_DATA_CONTENT] . NetworkPackage::PACKAGE_DATA_SEPARATOR
- );
- }
-
- /**
- * Checks whether the given package data is already processed by this fragmenter
- *
- * @param $packageData Raw package data array
- * @return $isProcessed Whether the package has been fragmented
- */
- private function isPackageProcessed (array $packageData) {
- // Get array index
- $index = $this->getProcessedPackagesIndex($packageData);
-
- // Is the array index there?
- $isProcessed = (
- (isset($this->processedPackages[$index]))
- &&
- ($this->processedPackages[$index] === TRUE)
- );
-
- // Return it
- return $isProcessed;
- }
-
- /**
- * Marks the given package data as processed by this fragmenter
- *
- * @param $packageData Raw package data array
- * @return void
- */
- private function markPackageDataProcessed (array $packageData) {
- // Remember it (until we may remove it)
- $this->processedPackages[$this->getProcessedPackagesIndex($packageData)] = TRUE;
- }
-
- /**
- * Getter for final hash from given package data
- *
- * @param $packageData Raw package data array
- * @return $finalHash Final hash for package data
- */
- private function getFinalHashFromPackageData (array $packageData) {
- // Make sure it is there
- assert(isset($this->processedPackages[$this->getProcessedPackagesIndex($packageData)]));
-
- // Return it
- return $this->processedPackages[$this->getProcessedPackagesIndex($packageData)];
- }
-
- /**
- * Get next chunk pointer for given final hash
- *
- * @param $finalHash Final hash to get current pointer for
- */
- private function getCurrentChunkPointer ($finalHash) {
- // Is the final hash valid?
- assert(strlen($finalHash) > 0);
-
- // Is the pointer already initialized?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
- assert(isset($this->chunkPointers[$finalHash]));
-
- // Return it
- return $this->chunkPointers[$finalHash];
- }
-
- /**
- * Advance the chunk pointer for given final hash
- *
- * @param $finalHash Final hash to advance the pointer for
- */
- private function nextChunkPointer ($finalHash) {
- // Is the pointer already initialized?
- assert(isset($this->chunkPointers[$finalHash]));
-
- // Count one up
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
- $this->chunkPointers[$finalHash]++;
- }
-
- /**
- * "Getter" for data chunk size of given hash.
- *
- * @param $hash Hash to substract it's length
- * @return $dataChunkSize The chunk size
- */
- private function getDataChunkSizeFromHash ($hash) {
- // Calculate real (data) chunk size
- $dataChunkSize = (
- // Real chunk size
- ($this->chunkSize / 8) -
- // Hash size
- strlen($hash) -
- // Length of sperators
- (strlen(self::CHUNK_DATA_HASH_SEPARATOR) * 2) -
- // Length of max serial number
- self::MAX_SERIAL_LENGTH
- );
-
- // This should be larger than zero bytes
- assert($dataChunkSize > 0);
-
- // Return it
- return $dataChunkSize;
- }
-
- /**
- * Generates a hash from raw data
- *
- * @param $rawData Raw data bytes to hash
- * @return $hash Hash from the raw data
- * @todo Implement a way to send non-announcement packages with extra-salt
- */
- private function generateHashFromRawData ($rawData) {
- /*
- * Get the crypto instance and hash the data with no extra salt because
- * the other peer doesn't have *this* peer's salt.
- */
- $hash = $this->getCryptoInstance()->hashString($rawData, '', FALSE);
-
- // Return it
- return $hash;
- }
-
- /**
- * Appends an end-of-package chunk to the chunk list for given chunk and
- * final hash. As of 23-March-2012 the format of this chunk will be as any
- * regular one to keep things easy (KISS) in ChunkHandler class.
- *
- * @param $lastChunk Last chunk raw data
- * @param $finalHash Final hash for raw (unencoded) data
- * @return void
- */
- private function appendEndOfPackageChunk ($lastChunk, $finalHash) {
- // Generate end-of-package marker
- $chunkData =
- self::END_OF_PACKAGE_IDENTIFIER .
- $finalHash . self::CHUNK_HASH_SEPARATOR .
- $this->generateHashFromRawData($lastChunk);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: Adding EOP chunk with size of ' . strlen($chunkData) . ',finalHash=' . $finalHash . ' ...');
-
- // Add it as regular chunk
- $this->addChunkData($finalHash, $chunkData);
- }
-
- /**
- * Splits the given encoded data into smaller chunks, the size of the final
- * and the SEPARATOR is being subtracted from chunk size to fit it into a
- * TCP package (512 bytes).
- *
- * @param $rawData Raw data string
- * @param $finalHash Final hash from the raw data
- * @return void
- */
- private function splitEncodedDataIntoChunks ($rawData, $finalHash) {
- // Make sure final hashes with at least 32 bytes can pass
- assert(strlen($finalHash) >= 32);
-
- // Calculate real (data) chunk size
- $dataChunkSize = $this->getDataChunkSizeFromHash($finalHash);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: dataChunkSize=' . $dataChunkSize);
-
- // Init variables
- $chunkHash = '';
- $chunkData = '';
-
- // Now split it up
- for ($idx = 0; $idx < strlen($rawData); $idx += $dataChunkSize) {
- // Get the next chunk
- $chunkData = substr($rawData, $idx, $dataChunkSize);
-
- // Add the chunk to the propper array and do all the stuff there
- $this->addChunkData($finalHash, $chunkData);
- } // END - for
-
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).');
-
- // Add end-of-package chunk
- $this->appendEndOfPackageChunk($chunkData, $finalHash);
- }
-
- /**
- * Adds the given chunk (raw data) to the proper array and hashes it for
- * later verfication.
- *
- * @param $finalHash Final hash for faster processing
- * @param $chunkData Raw chunk data
- * @param $prepend Whether append (default) or prepend the chunk
- * @return void
- */
- private function addChunkData ($finalHash, $chunkData, $prepend = FALSE) {
- // Hash it
- $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', FALSE);
-
- // Prepend the hash to the chunk
- $rawData = (
- $rawDataHash . self::CHUNK_DATA_HASH_SEPARATOR .
- $this->getNextHexSerialNumber($finalHash) . self::CHUNK_DATA_HASH_SEPARATOR .
- $chunkData . self::CHUNK_SEPARATOR
- );
-
- // Make sure the chunk is not larger than a TCP package can hold
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: assert: ' . strlen($rawData) . '/' . NetworkPackage::TCP_PACKAGE_SIZE . ' ...');
- // @TODO This assert broke packages where the hash chunk was very large: assert(strlen($rawData) <= NetworkPackage::TCP_PACKAGE_SIZE);
-
- // Add it to the array
- if ($prepend === TRUE) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: Prepending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
- array_unshift($this->chunkHashes[$finalHash], $rawDataHash);
- array_unshift($this->chunks[$finalHash] , $rawData);
- } else {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: Appending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
-
- // Is the array there?
- if (!isset($this->chunks[$finalHash])) {
- // Then initialize it
- $this->chunks[$finalHash] = array();
- $this->chunkHashes[$finalHash] = array();
- } // END - if
-
- // Add both
- array_push($this->chunks[$finalHash] , $rawData);
- array_push($this->chunkHashes[$finalHash], $rawDataHash);
- }
- }
-
- /**
- * Prepends a chunk (or more) with all hashes from all chunks + final chunk.
- *
- * @param $finalHash Final hash from the raw data
- * @return void
- */
- private function prependHashChunk ($finalHash) {
- // "Implode" the whole array of hashes into one string
- $rawData = self::HASH_CHUNK_IDENTIFIER . implode(self::CHUNK_HASH_SEPARATOR, $this->chunkHashes[$finalHash]);
-
- // Prepend chunk
- $this->addChunkData($finalHash, $rawData, TRUE);
- }
-
- /**
- * "Getter" for the next hexadecimal-encoded serial number
- *
- * @param $finalHash Final hash
- * @return $encodedSerialNumber The next hexadecimal-encoded serial number
- */
- public function getNextHexSerialNumber ($finalHash) {
- // Assert on maximum serial number length
- assert(isset($this->serialNumber[$finalHash]));
- assert($this->serialNumber[$finalHash] <= $this->maxSerialNumber);
-
- // Encode the current serial number
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: serialNumber[' . $finalHash . ']=' . $this->serialNumber[$finalHash]);
- $encodedSerialNumber = $this->dec2Hex($this->serialNumber[$finalHash], self::MAX_SERIAL_LENGTH);
-
- // Count one up
- $this->serialNumber[$finalHash]++;
-
- // Return the encoded serial number
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: encodedSerialNumber=' . $encodedSerialNumber);
- return $encodedSerialNumber;
- }
-
- /**
- * This method does "implode" the given package data array into one long
- * string, splits it into small chunks, adds a serial number and checksum
- * 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 Raw package data array
- * @param $helperInstance An instance of a ConnectionHelper class
- * @return $finalHash Final hash for faster processing
- * @todo $helperInstance is unused
- */
- public function fragmentPackageArray (array $packageData, ConnectionHelper $helperInstance) {
- // Is this package already fragmented?
- if (!$this->isPackageProcessed($packageData)) {
- // First we need to "implode" the array
- $rawData = implode(NetworkPackage::PACKAGE_DATA_SEPARATOR, $packageData);
-
- // Generate the final hash from the raw data (not encoded!)
- $finalHash = $this->generateHashFromRawData($rawData);
-
- // Remember it
- $this->processedPackages[$this->getProcessedPackagesIndex($packageData)] = $finalHash;
-
- // Init pointer and reset serial number
- $this->initPointer($finalHash);
- $this->resetSerialNumber($finalHash);
-
- // Split the encoded data into smaller chunks
- $this->splitEncodedDataIntoChunks($rawData, $finalHash);
-
- // Prepend a chunk with all hashes together
- $this->prependHashChunk($finalHash);
-
- // Mark the package as fragmented
- $this->markPackageDataProcessed($packageData);
- } else {
- // Get the final hash from the package data
- $finalHash = $this->getFinalHashFromPackageData($packageData);
- }
-
- // Return final hash
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
- return $finalHash;
- }
-
- /**
- * This method gets the next chunk from the internal FIFO which should be
- * sent to the given recipient. It will return an associative array where
- * the key is the chunk hash and value the raw chunk data.
- *
- * @param $finalHash Final hash for faster lookup
- * @return $rawDataChunk Raw package data chunk
- * @throws AssertionException If $finalHash was not 'TRUE'
- */
- public function getNextRawDataChunk ($finalHash) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('PACKAGE-FRAGMENTER[' . __METHOD__ . ':' . __LINE__ . ']: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
-
- try {
- // Get current chunk index
- $current = $this->getCurrentChunkPointer($finalHash);
- } catch (AssertionException $e) {
- // This may happen when the final hash is TRUE
- if ($finalHash === TRUE) {
- // Set current to null
- $current = NULL;
- } else {
- // Throw the exception
- throw $e;
- }
- }
-
- // If there is no entry left, return an empty array
- if ((!isset($this->chunkHashes[$finalHash][$current])) || (!isset($this->chunks[$finalHash][$current]))) {
- // No more entries found
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__. ': finalHash=' . $finalHash . ',current=' . $current . ' - No more entries found!');
- return array();
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__. ': finalHash=' . $finalHash . ',current=' . $current . ',chunkHashes()=' . count($this->chunkHashes[$finalHash]) .' - Entry choosen ...');
-
- // Generate the array
- $rawDataChunk = array(
- $this->chunkHashes[$finalHash][$current] => $this->chunks[$finalHash][$current]
- );
-
- // Count one index up
- $this->nextChunkPointer($finalHash);
-
- // Return the chunk array
- return $rawDataChunk;
- }
-
- /**
- * Resets the serial number to zero for given final hash
- *
- * @param $finalHash Final hash to reset counter for
- * @return void
- */
- public function resetSerialNumber ($finalHash) {
- // Final hash must be set
- assert((is_string($finalHash)) && (!empty($finalHash)));
-
- // Reset/set serial number
- $this->serialNumber[$finalHash] = 0;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- *
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Pool extends BasePool implements Poolable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listenerInstance A Listenable instance
- * @return $poolInstance An instance a Poolable class
- */
- public final static function create???Pool (Listenable $listenerInstance) {
- // Get new instance
- $poolInstance = new ???Pool();
-
- // Set the application instance
- $poolInstance->setListenerInstance($listenerInstance);
-
- // Return the prepared instance
- return $poolInstance;
- }
-
- /**
- * Adds a listener instance to this pool
- *
- * @param $poolInstance An instance of a Listenable class
- * @return void
- * @todo 0% done
- */
- public function addListener (Listenable $poolInstance) {
- $this->partialStub('Need to implement this method. listenerInstance=' . $poolInstance->__toString());
- }
-}
-
-//
-?>
+++ /dev/null
-<?php
-/**
- * A general pool class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BasePool extends BaseHubSystem implements Visitable {
- /**
- * Socket array elements
- */
- const SOCKET_ARRAY_RESOURCE = 'resource';
- const SOCKET_ARRAY_CONN_TYPE = 'connection_type';
-
- /**
- * A list of pool entries
- */
- private $poolEntriesInstance = NULL;
-
- /**
- * An array with all valid connection types
- */
- private $connectionTypes = array();
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Init the pool entries
- $this->poolEntriesInstance = ObjectFactory::createObjectByConfiguredName('pool_entries_list_class');
-
- // Init array of connection types
- $this->connectionTypes = array(
- BaseConnectionHelper::CONNECTION_TYPE_INCOMING,
- BaseConnectionHelper::CONNECTION_TYPE_OUTGOING,
- BaseConnectionHelper::CONNECTION_TYPE_SERVER
- );
- }
-
- /**
- * Getter for pool entries instance
- *
- * @return $poolEntriesInstance An instance for pool entries (list)
- */
- public final function getPoolEntriesInstance () {
- return $this->poolEntriesInstance;
- }
-
- /**
- * Adds an instance to a pool segment
- *
- * @param $group Name of the pool group
- * @param $poolSegment Name of the pool segment
- * @param $visitableInstance An instance of a class that should bed added to the pool
- * @return void
- */
- protected final function addInstance ($group, $poolName, Visitable $visitableInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: group=' . $group . ',poolName=' . $poolName . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!');
-
- // Make sure the group is not 'invalid'
- assert($group != 'invalid');
-
- // Is the pool group there?
- if (!$this->getPoolEntriesInstance()->isGroupSet($group)) {
- // Create the missing pool group
- $this->getPoolEntriesInstance()->addGroup($group);
- } // END - if
-
- // Add it to given pool group
- $this->getPoolEntriesInstance()->addInstance($group, $poolName, $visitableInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Adds an entry to the pool
- *
- * @param $poolEntry The new pool entry that should be added
- * @return void
- */
- protected final function addPoolEntry ($poolEntry) {
- $this->getPoolEntriesInstance()->addEntry('pool', $poolEntry);
- }
-
- /**
- * Accepts the visitor to process the visit "request"
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - CALLED!');
-
- // Visit this pool
- $visitorInstance->visitPool($this);
-
- // Do we have a registry instance for this visitor's iterator?
- if (Registry::getRegistry()->instanceExists($visitorInstance->getVisitorMode() . '_pool_iterator')) {
- // Get the instance from registry
- $iteratorInstance = Registry::getRegistry()->getInstance($visitorInstance->getVisitorMode() . '_pool_iterator');
- } else {
- // Get a new iterator instance
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance()));
-
- // Add it to the registry
- Registry::getRegistry()->addInstance($visitorInstance->getVisitorMode() . '_pool_iterator', $iteratorInstance);
- }
-
- // Reset the counter
- $iteratorInstance->rewind();
-
- // Visit all registered entries
- while ($iteratorInstance->valid()) {
- // Get current entry
- $poolEntry = $iteratorInstance->current();
-
- // Is this entry visitable?
- if ($poolEntry instanceof Visitable) {
- // Visit this entry as well
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-POOL[' . __METHOD__ . ':' . __LINE__ . ']: Going to visit pooled object ' . $poolEntry->__toString() . ' with visitor ' . $visitorInstance->__toString() . ' ...');
- $poolEntry->accept($visitorInstance);
- } else {
- // Cannot visit this entry
- $this->partialStub('Pool entry with key ' . $iteratorInstance->key() . ' has improper type ' . gettype($poolEntry) . ', reason: not implementing Visitable.');
- }
-
- // Advance to next entry
- $iteratorInstance->next();
- } // END - while
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited - EXIT!');
- }
-
- /**
- * Gets the array from specified list
- *
- * @param $list The list identifier we should return
- * @return $array The requested array
- */
- protected final function getArrayFromList ($list) {
- // Get the array
- $array = $this->getPoolEntriesInstance()->getArrayFromList($list);
-
- // Return it
- return $array;
- }
-
- /**
- * Checks whether the given connection type is valid
- *
- * @param $connectionType Type of connection, can be 'incoming', 'outgoing' or 'server'
- * @return $isValid Whether the provided connection type is valid
- */
- protected function isValidConnectionType ($connectionType) {
- // Is it valid?
- $isValid = in_array($connectionType, $this->connectionTypes, TRUE);
-
- // Return result
- return $isValid;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A default listener pool
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DefaultListenerPool extends BasePool implements PoolableListener {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $nodeInstance A NodeHelper instance
- * @return $listenerInstance An instance a prepared listener class
- */
- public static final function createDefaultListenerPool (NodeHelper $nodeInstance) {
- // Get new instance
- $listenerInstance = new DefaultListenerPool();
-
- // Return the prepared instance
- return $listenerInstance;
- }
-
- /**
- * Adds a listener instance to this pool
- *
- * @param $listenerInstance An instance of a Listenable class
- * @return void
- */
- public function addListener (Listenable $listenerInstance) {
- // Add this listener instance to the instance list
- parent::addInstance($listenerInstance->getProtocolName(), 'listener', $listenerInstance);
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput(
- 'POOL[' . __METHOD__ . ':' . __LINE__ . ']: Listener ' . $listenerInstance->__toString() .
- ' listening to ' . $listenerInstance->getListenAddress() . ':' .
- $listenerInstance->getListenPort() . ' added to listener pool.'
- );
- }
-
- /**
- * Run the shutdown seqeuence by a Visitor Pattern
- *
- * @return void
- */
- public function doShutdown () {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down listener pool - CALLED!');
-
- // Get a new visitor
- $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_listener_pool_visitor_class');
-
- // Start visiting
- $this->accept($visitorInstance);
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down listener pool - EXIT!');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A default peer pool class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DefaultPeerPool extends BasePool implements PoolablePeer {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listenerInstance A Listenable instance
- * @return $poolInstance An instance a Poolable class
- */
- public static final function createDefaultPeerPool (Listenable $listenerInstance) {
- // Get new instance
- $poolInstance = new DefaultPeerPool();
-
- // Set the application instance
- $poolInstance->setListenerInstance($listenerInstance);
-
- // Return the prepared instance
- return $poolInstance;
- }
-
- /**
- * Validates given socket
- *
- * @param $socketResource A valid socket resource
- * @return void
- * @throws InvalidSocketException If the given socket has an error
- */
- private function validateSocket ($socketResource) {
- // Is it a valid resource?
- if (!is_resource($socketResource)) {
- // Throw an exception
- throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
-
- // Get error code
- $errorCode = socket_last_error($socketResource);
-
- // Is it without any errors?
- if ($errorCode > 0) {
- // Handle the socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
- /*
- // Get error message
- $errorMessage = socket_strerror($errorCode);
-
- // Shutdown this socket
- $this->getListenerInstance()->shutdownSocket($socketResource);
-
- // And throw again
- throw new InvalidSocketException(array($this, $socketResource, $errorCode, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
- }
-
- /**
- * Adds a socket resource to the peer pool
- *
- * @param $socketResource A valid (must be!) socket resource
- * @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server'
- * @return void
- * @throws InvalidSocketException If the given resource is invalid or errorous
- * @throws InvalidConnectionTypeException If the provided connection type is not valid
- */
- public function addPeer ($socketResource, $connectionType) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DEFAULT-PEER-POOL[' . __METHOD__ . ':' . __LINE__ . ']: socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',connectionType=' . $connectionType . ' - CALLED!');
-
- // Validate the socket
- $this->validateSocket($socketResource);
-
- // Is the connection type valid?
- if (!$this->isValidConnectionType($connectionType)) {
- // Is not a valid connection type!
- throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
- } // END - if
-
- // Default is this peer's IP
- $peerName = '0.0.0.0';
-
- // The socket resource should not match server socket
- if ($socketResource != $this->getListenerInstance()->getSocketResource()) {
- // Try to determine the peer's IP number
- if (!socket_getpeername($socketResource, $peerName)) {
- // Handle the socket error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
- /*
- // Get last error
- $lastError = socket_last_error($socketResource);
-
- // Doesn't work!
- throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
- */
- } // END - if
- } else {
- // Server sockets won't work with socket_getpeername()
- self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Socket resource is server socket (' . $socketResource . '). This is not a bug.');
- }
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Adding peer ' . $peerName . ',socketResource=' . $socketResource . ',type=' . $connectionType);
-
- // Construct the array
- $socketArray = array(
- self::SOCKET_ARRAY_RESOURCE => $socketResource,
- self::SOCKET_ARRAY_CONN_TYPE => $connectionType
- );
-
- // Add it finally to the pool
- $this->addPoolEntry($socketArray);
- }
-
- /**
- * Getter for array of all socket resources
- *
- * @return $sockets An array with all sockets
- */
- public final function getAllSockets () {
- // Get the list
- $sockets = $this->getArrayFromList('pool');
-
- // Return it
- return $sockets;
- }
-
- /**
- * Getter for array of all socket arrays
- *
- * @return $sockets An array with all socket arrays
- */
- public final function getAllSingleSockets () {
- // Get the array list
- $socketArrays = $this->getArrayFromList('pool');
-
- // Init socket array
- $sockets = array();
-
- // "Walk" through all socket arrays
- foreach ($socketArrays as $socketArray) {
- // Add the socket
- array_push($sockets, $socketArray[self::SOCKET_ARRAY_RESOURCE]);
- } // END - foreach
-
- // Return it
- return $sockets;
- }
-
- /**
- * "Getter" for all sockets of specified type
- *
- * @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server'
- * @return $sockets An array with sockets of given type
- * @throws InvalidConnectionTypeException If the provided connection type is not valid
- */
- public function getSocketsByConnectionType ($connectionType) {
- // Is the connection type valid?
- if (!$this->isValidConnectionType($connectionType)) {
- // Is not a valid connection type!
- throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
- } // END - if
-
- // Get the array list
- $socketArrays = $this->getArrayFromList('pool');
-
- // Init socket array
- $sockets = array();
-
- // "Walk" through all socket arrays
- foreach ($socketArrays as $socketArray) {
- // Does it match?
- if ($socketArray[self::SOCKET_ARRAY_CONN_TYPE] === $connectionType) {
- // Add the socket
- array_push($sockets, $socketArray[self::SOCKET_ARRAY_RESOURCE]);
- } // END - if
- } // END - foreach
-
- // Return it
- return $sockets;
- }
-
- /**
- * "Getter" for a valid socket resource from given packae data.
- *
- * @param $packageData Raw package data
- * @param $connectionType Type of connection, can be 'incoming', 'outgoing', 'server' or default
- * @return $socketResource Socket resource
- * @throws InvalidConnectionTypeException If the provided connection type is not valid
- */
- public function getSocketFromPackageData (array $packageData, $connectionType = NULL) {
- // Default is no socket
- $socketResource = FALSE;
-
- // Resolve recipient (UNL) into a handler instance
- $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
-
- // Get UNL data
- $unlData = $handlerInstance->getUniversalNodeLocatorDataArray();
-
- // Make sure it is a valid Universal Node Locator array (3 elements)
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[' . UniversalNodeLocator::UNL_PART_ADDRESS . ']=' . $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] . ',unlData[' . UniversalNodeLocator::UNL_PART_PORT . ']=' . $unlData[UniversalNodeLocator::UNL_PART_PORT] . ' ...');
-
- // Default is all sockets
- $sockets = $this->getAllSockets();
-
- // Is connection type set?
- if ((is_string($connectionType)) && ($this->isValidConnectionType($connectionType))) {
- // Then get a list of this type
- $sockets = $this->getSocketsByConnectionType($connectionType);
- } elseif (is_string($connectionType)) {
- // Is not a valid connection type!
- throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
- }
-
- // Get all sockets and check them, skip the server socket
- foreach ($sockets as $socketArray) {
- // Is this a server socket?
- if ($socketArray[self::SOCKET_ARRAY_RESOURCE] === $this->getListenerInstance()->getSocketResource()) {
- // Skip 'server' sockets (local socket)
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Skipping server socket ' . $socketArray[self::SOCKET_ARRAY_RESOURCE] . ' ...');
- continue;
- } // END - if
-
- // Try to get the "peer"'s name
- if (!socket_getpeername($socketArray[self::SOCKET_ARRAY_RESOURCE], $peerIp)) {
- // Handle the socket error with given package data
- $this->handleSocketError(__METHOD__, __LINE__, $socketArray[self::SOCKET_ARRAY_RESOURCE], explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
- } // END - if
-
- // Get
- // If the "peer" IP and recipient is same, use it
- if ($peerIp == $unlData[UniversalNodeLocator::UNL_PART_ADDRESS]) {
- // IPs match, so take the socket and quit this loop
- $socketResource = $socketArray[self::SOCKET_ARRAY_RESOURCE];
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: peerIp=' . $peerIp . ' matches with recipient IP address. Taking socket=' . $socketArray[self::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[self::SOCKET_ARRAY_CONN_TYPE]);
- break;
- } // END - if
- } // END - foreach
-
- // Return the determined socket resource
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: socketResource[' . gettype($socketResource) . ']=' . $socketResource);
- return $socketResource;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? producer class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Producer extends BaseProducer implements Producer, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $producerInstance An instance of a Producer class
- */
- public final static function create???Producer () {
- // Get new instance
- $producerInstance = new ???Producer();
-
- // Return the prepared instance
- return $producerInstance;
- }
-
- /**
- * Initializes the producer
- *
- * @return void
- */
- protected function initProducer () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general Producer class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
- */
-abstract class BaseProducer extends BaseFrameworkSystem {
- /**
- * Outgoing work-queue
- */
- private $outgoingQueueInstance = NULL;
-
- /**
- * Incoming raw data/items queue
- */
- private $incomingQueueInstance = NULL;
-
- /**
- * Stacker name for incoming work
- */
- const STACKER_NAME_IN_QUEUE = 'incoming_queue';
-
- /**
- * Stacker name for outgoing work
- */
- const STACKER_NAME_OUT_QUEUE = 'outgoing_queue';
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Initialize all producers
- $this->initProducer();
-
- // Get miner instance
- $minerInstance = Registry::getRegistry()->getInstance('miner');
-
- // Change state to next state
- $minerInstance->blockProducerHasInitialized($this);
-
- // Initialize work queue (out-going, produced items)
- $this->initWorkQueue();
- }
-
- /**
- * Getter for outgoing work queue
- *
- * @param $outgoingQueueInstance The outgoing work queue instance
- */
- protected final function getOutgoingQueueInstance () {
- return $this->outgoingQueueInstance;
- }
-
- /**
- * Setter for outgoing work queue
- *
- * @param $outgoingQueueInstance The outgoing work queue instance
- * @return void
- */
- private final function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) {
- $this->outgoingQueueInstance = $outgoingQueueInstance;
- }
-
- /**
- * Getter for incoming raw data/items queue
- *
- * @param $incomingQueueInstance The incoming raw data/items queue instance
- */
- protected final function getIncomingQueueInstance () {
- return $this->incomingQueueInstance;
- }
-
- /**
- * Setter for incoming raw data/items queue
- *
- * @param $incomingQueueInstance The incoming raw data/items queue instance
- * @return void
- */
- private final function setIncomingQueueInstance (Stackable $incomingQueueInstance) {
- $this->incomingQueueInstance = $incomingQueueInstance;
- }
-
- /**
- * Initializes this producer, this method must be overwritten.
- *
- * @return void
- */
- abstract protected function initProducer();
-
- /**
- * Initializes the work queue which is being used for outgoing, produced
- * items.
- *
- * @return void
- */
- protected function initWorkQueue () {
- // Get an instance and set it in this producer
- $this->setOutgoingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_outgoing_queue'));
-
- // Init the queue
- $this->initOutgoingQueue();
-
- // Get an instance and set it in this producer
- $this->setIncomingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_incoming_queue'));
-
- // Init the queue
- $this->initIncomingQueue();
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: All queues have been initialized.');
- }
-
- /**
- * Inits the out-going queue stack
- *
- * @return void
- */
- protected function initOutgoingQueue () {
- $this->getOutgoingQueueInstance()->initStack(self::STACKER_NAME_OUT_QUEUE, TRUE);
- }
-
- /**
- * Adds an entry to the out-going work queue
- *
- * @param $value The value to be added to the out-going work queue
- * @return void
- */
- protected function addValueToOutgoingQueue ($value) {
- $this->getOutgoingQueueInstance()->pushNamed(self::STACKER_NAME_OUT_QUEUE, $value);
- }
-
- /**
- * Checks whether a configurable out-going queue limit has been reached
- *
- * @param $configEntry Configuration entry where the limit is stored
- * @return $isReached Whether the limit is reached
- */
- protected function isOutgoingQueueLimitReached ($configEntry) {
- return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getOutgoingQueueInstance()->getStackCount(self::STACKER_NAME_OUT_QUEUE));
- }
-
- /**
- * Inits the incoming queue stack
- *
- * @return void
- */
- protected function initIncomingQueue () {
- $this->getIncomingQueueInstance()->initStack(self::STACKER_NAME_IN_QUEUE, TRUE);
- }
-
- /**
- * Adds an entry to the incoming work queue
- *
- * @param $value The value to be added to the incoming work queue
- * @return void
- */
- protected function addValueToIncomingQueue ($value) {
- $this->getIncomingQueueInstance()->pushNamed(self::STACKER_NAME_IN_QUEUE, $value);
- }
-
- /**
- * Checks whether a configurable incoming queue limit has been reached
- *
- * @param $configEntry Configuration entry where the limit is stored
- * @return $isReached Whether the limit is reached
- */
- protected function isIncomingQueueLimitReached($configEntry) {
- return ($this->getConfigInstance()->getConfigEntry($configEntry) <= $this->getIncomingQueueInstance()->getStackCount(self::STACKER_NAME_IN_QUEUE));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A general KeyProducer class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
- */
-abstract class BaseKeyProducer extends BaseProducer {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Init key producer
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general UnitProducer class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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/>.
- */
-abstract class BaseUnitProducer extends BaseProducer {
- /**
- * Work/test unit status
- */
- const UNIT_STATUS_AVAILABLE = 'available'; // Available for crunching
- const UNIT_STATUS_PENDING = 'pending'; // Is being crunched at the moment
- const UNIT_STATUS_DONE = 'done'; // Is already crunched/finished
-
- /**
- * Work or test unit?
- */
- const UNIT_TYPE_TEST_UNIT = 'test_unit';
- const UNIT_TYPE_TEST_WORK = 'work_unit';
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A CruncherKey producer class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherKeyProducer extends BaseKeyProducer implements KeyProducer, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $producerInstance An instance of a Producer class
- */
- public final static function createCruncherKeyProducer () {
- // Get new instance
- $producerInstance = new CruncherKeyProducer();
-
- // Get a helper instance, we now only need this for the key iterator
- $helperInstance = ObjectFactory::createObjectByConfiguredName('crypto_random_message_helper_class', array('test'));
-
- // Next get an iterator, again the helper will do that for us
- $iteratorInstance = $helperInstance->getKeyIterator();
-
- // Set it in the producer
- $producerInstance->setIteratorInstance($iteratorInstance);
-
- // Return the prepared instance
- return $producerInstance;
- }
-
- /**
- * Initializes the producer. This method satisfies the abstract BaseProducer
- * class.
- *
- * @return void
- * @todo Find something for init phase of this key producer
- */
- protected function initProducer () {
- }
-
- /**
- * Initializes the executor, whatever it does.
- *
- * @return void
- * @todo 0% done
- */
- public function initExecutor (Stateable $stateInstance) {
- $this->partialStub('Maybe implement this method?');
- }
-
- /**
- * Produces some keys and pushes them onto the queue
- *
- * @param $stateInstance An instance of a Stateable instance
- * @return void
- * @todo ~30% done
- */
- public function produceKeys (Stateable $stateInstance) {
- // Is this cruncher virgin?
- if (!$stateInstance->isCruncherStateVirgin()) {
- // This cruncher is not virgin, so skip it
- self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: The cruncher is not virgin. stateInstance=' . $stateInstance->__toString() . '');
- return;
- } elseif (!$this->getIteratorInstance()->valid()) {
- // This producer's iterator has finished its assignment
- self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: Finished creating keys. iteratorInstance=' . $this->getIteratorInstance()->__toString() . '');
- return;
- }
-
- /*
- * Now we need to create an iterator, just as for the work units,
- * to create new keys from the encrypted message. The iterator will
- * not iterate over an object nor a collection. It will instead
- * encapsulate the "key production" into a class and not in a simple
- * for() loop. These keys then needs to be bundled into test units
- * and stored to database for later re-usage.
- */
-
- /*
- * Get current key (which is not the key of the iterator) This is always
- * an ASCII string.
- */
- $currentKey = $this->getIteratorInstance()->current();
-
- // Add it to the out-going work queue
- $this->addValueToOutgoingQueue($currentKey);
-
- // Is the per-work unit limit reached?
- if ($this->isOutgoingQueueLimitReached('cruncher_per_unit_key_limit')) {
- // @TODO Send the produced key bundle to the unit producer's input queue
- self::createDebugInstance(__CLASS__)->debugOutput('currentKey(b64)="' . base64_encode($currentKey) . '" needs to be processed.');
-
- // At last re-init the stack
- $this->initOutgoingQueue();
- } // END - if
-
- // Continue with next one
- $this->getIteratorInstance()->next();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A CruncherTestUnit producer class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $producerInstance An instance of a Producer class
- */
- public final static function createCruncherTestUnitProducer () {
- // Get new instance
- $producerInstance = new CruncherTestUnitProducer();
-
- // Test units have a helper class that wraps the source
- $helperInstance = ObjectFactory::createObjectByConfiguredName('crypto_random_message_helper_class', array('test'));
-
- // So set it in the producer
- $producerInstance->setHelperInstance($helperInstance);
-
- // Return the prepared instance
- return $producerInstance;
- }
-
- /**
- * Initializes the producer. This method satisfies the abstract BaseProducer
- * class.
- *
- * @return void
- */
- protected function initProducer () {
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('cruncher_test_unit_producer_template_class');
-
- // Load the template
- $templateInstance->loadXmlTemplate();
-
- // Render the XML content
- $templateInstance->renderXmlContent();
-
- // And set it in this cruncher
- $this->setTemplateInstance($templateInstance);
- }
-
- /**
- * Prepares the produces of some test units and pushes them onto the queue
- *
- * @param $stateInstance An instance of a Stateable instance
- * @return void
- * @todo ~60% done
- */
- public function initUnitProduction (Stateable $stateInstance) {
- // First get a database wrapper because we want to permanently store test units
- $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('cruncher_unit_db_wrapper_class');
-
- // Do we have some entries?
- if ($wrapperInstance->isTestUnitProduced()) {
- // Entries found
- // @TODO Unfinished work here
- $this->debugInstance();
-
- // The state must be changed because ...
- $stateInstance->someFooStateChange();
- } else {
- // Get an encrypted, random message from our source
- $encryptedMessage = $this->getHelperInstance()->generateRandomMessage();
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: An encrypted, random message has been generated. Generating keys ...');
-
- // Set the encrypted message in the template instance
- $this->getTemplateInstance()->assignVariable('encrypted_message', $encryptedMessage);
-
- // The state must be changed because we have a new message
- $stateInstance->encryptedMessageGenerated();
- }
- }
-
- /**
- * Initializes the executor, whatever it does.
- *
- * @return void
- * @todo Maybe unfinished
- */
- public function initExecutor (Stateable $stateInstance) {
- $this->partialStub('Maybe implement this method?');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A MinerRealGenesisBlock producer class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 MinerRealGenesisBlockProducer extends BaseBlockProducer implements BlockProducer, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $producerInstance An instance of a Producer class
- */
- public final static function createMinerRealGenesisBlockProducer () {
- // Get new instance
- $producerInstance = new MinerRealGenesisBlockProducer();
-
- // Get a (minable) hash block instance
- $minableInstance = ObjectFactory::createObjectByConfiguredName('miner_real_hash_block_class');
-
- // Set it here
- $producerInstance->setMinableInstance($minableInstance);
-
- // Return the prepared instance
- return $producerInstance;
- }
-
- /**
- * Initializes the producer. This method satisfies the abstract BaseProducer
- * class.
- *
- * @return void
- * @todo 0% done
- */
- protected function initProducer () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Initializes the executor, whatever it does.
- *
- * @return void
- * @todo 0% done
- */
- public function initExecutor (Stateable $stateInstance) {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Prepares the produces of some test units and pushes them onto the queue
- *
- * @param $stateInstance An instance of a Stateable instance
- * @return void
- * @todo ~5% done
- */
- public function prepareBlockProduction (Stateable $stateInstance) {
- // The state must be 'booting'
- $stateInstance->validateMinerStateIsBooting();
-
- /*
- * Now that the miner is booting a genesis block for real mining can be
- * created.
- */
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A MinerTestGenesisBlock producer class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 MinerTestGenesisBlockProducer extends BaseBlockProducer implements BlockProducer, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $producerInstance An instance of a Producer class
- */
- public final static function createMinerTestGenesisBlockProducer () {
- // Get new instance
- $producerInstance = new MinerTestGenesisBlockProducer();
-
- // Get a (minable) hash block instance
- $minableInstance = ObjectFactory::createObjectByConfiguredName('miner_test_hash_block_class');
-
- // Set it here
- $producerInstance->setMinableInstance($minableInstance);
-
- // Return the prepared instance
- return $producerInstance;
- }
-
- /**
- * Initializes the producer. This method satisfies the abstract BaseProducer
- * class.
- *
- * @return void
- * @todo 0% done
- */
- protected function initProducer () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Initializes the executor, whatever it does.
- *
- * @return void
- * @todo 0% done
- */
- public function initExecutor (Stateable $stateInstance) {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Prepares the produces of some test units and pushes them onto the queue
- *
- * @param $stateInstance An instance of a Stateable instance
- * @return void
- * @todo ~5% done
- */
- public function prepareBlockProduction (Stateable $stateInstance) {
- // The state must be 'booting'
- $stateInstance->validateMinerStateIsBooting();
-
- /*
- * Now that the miner is booting a "genesis" block for testing purposes
- * can be created. The real "genesis" block will be created differently
- * to this.
- */
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general BlockProducer class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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/>.
- */
-abstract class BaseBlockProducer extends BaseProducer {
- /**
- * Block status
- */
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// @DEPRECATED
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? recipient
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Recipient extends BaseRecipient implements Recipient {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $recipientInstance An instance of a Recipient class
- */
- public final static function create???Recipient () {
- // Get new instance
- $recipientInstance = new ???Recipient();
-
- // Return the prepared instance
- return $recipientInstance;
- }
-
- /**
- * 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
- * @return $resolved Resolved recipient or VOID if only the set list has been filled
- * @throws FrameworkException Could throw different exceptions back depending on implementation
- * @todo 0% done
- */
- public function resolveRecipient ($recipient, Listable $listInstance) {
- // Make sure the recipient is valid
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('!!!-RECIPIENT: recipient=' . $recipient);
- assert($recipient == '|||');
- $this->partialStub('Please implement this method. recipient=' . $recipient);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general Recipient class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseRecipient extends BaseHubSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A DHT recipient
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtRecipient extends BaseRecipient implements Recipient {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $recipientInstance An instance of a Recipient class
- */
- public final static function createDhtRecipient () {
- // Get new instance
- $recipientInstance = new DhtRecipient();
-
- // Return the prepared instance
- return $recipientInstance;
- }
-
- /**
- * Tries to resolve given recipient into session ids or Universal Node Locator
- * depending on implementation (hint: Template Method Pattern). This
- * 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 Valid package data array
- * @return void
- * @throws FrameworkException Could throw different exceptions depending on implementation
- */
- public function resolveRecipient ($recipient, Listable $listInstance, array $packageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient . ' - CALLED!');
-
- // Make sure the recipient is valid
- assert($recipient == NetworkPackage::NETWORK_TARGET_DHT);
-
- // Get recipient discovery instance
- $discoverInstance = ObjectFactory::createObjectByConfiguredName('dht_recipient_discovery_class');
-
- // "Discover" recipients by given package data
- $recipients = $discoverInstance->resolveRecipientsByPackageData($packageData);
-
- // Now "walk" through all elements and add them to the list
- foreach ($recipients as $recipient) {
- // These array elements must exist for this loop:
- // @TODO Unfinished
- die(__METHOD__ . ':recipient=' . print_r($recipient, TRUE));
- assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]));
-
- // Put ip and port both together
- $unl = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS];
-
- // Add it to the list
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: Calling listInstance->addEntry(' . $unl . ') ...');
- $listInstance->addEntry('unl', $unl);
- } // END - foreach
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient . ' - EXIT!');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Direct recipient
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DirectRecipient extends BaseRecipient implements Recipient {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $recipientInstance An instance of a Recipient class
- */
- public final static function createDirectRecipient () {
- // Get new instance
- $recipientInstance = new DirectRecipient();
-
- // Return the prepared instance
- return $recipientInstance;
- }
-
- /**
- * 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 Valid package data array
- * @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, array $packageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient);
-
- // "Explode" all recipients
- $recipients = explode(NetworkPackage::PACKAGE_RECIPIENT_SEPARATOR, $recipient);
-
- // Is maximum reached?
- assert(count($recipients) <= $this->getConfigInstance()->getConfigEntry('package_recipient_max_count'));
-
- // Try it on all
- foreach ($recipients as $recipient) {
- // Try to sole a single recipient
- $unlData = HubTools::resolveSessionId($recipient);
-
- // Add it as recipient
- $listInstance->addEntry('unl', $unlData);
- } // END - foreach
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Self recipient
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 SelfRecipient extends BaseRecipient implements Recipient {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $recipientInstance An instance of a Recipient class
- */
- public final static function createSelfRecipient () {
- // Get new instance
- $recipientInstance = new SelfRecipient();
-
- // Return the prepared instance
- return $recipientInstance;
- }
-
- /**
- * 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 Valid package data array
- * @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, array $packageData) {
- // Make sure the recipient is valid
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient);
- // @TODO Add more checks on data
- assert($recipient == NetworkPackage::NETWORK_TARGET_SELF);
-
- // Determine IP or 'external_address' if set
- $unl = HubTools::determineOwnExternalAddress();
-
- // Is it not empty?
- if (!empty($unl)) {
- // Add it to the list
- $listInstance->addEntry('unl', $unl);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Upper recipient
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UpperRecipient extends BaseRecipient implements Recipient {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $recipientInstance An instance of a Recipient class
- */
- public final static function createUpperRecipient () {
- // Get new instance
- $recipientInstance = new UpperRecipient();
-
- // Return the prepared instance
- return $recipientInstance;
- }
-
- /**
- * 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 Valid package data array
- * @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, array $packageData) {
- // Make sure the recipient is valid
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('UPPER-RECIPIENT: recipient=' . $recipient);
- assert($recipient == NetworkPackage::NETWORK_TARGET_UPPER);
-
- // Get all bootstrap nodes
- foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlData) {
- // Is maximum reached?
- if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
- // Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER[' . __METHOD__ . ':' . __LINE__ . ']: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
-
- // Then stop adding more
- break;
- } // END - if
-
- // Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER[' . __METHOD__ . ':' . __LINE__ . ']: Adding node ' . print_r($unlData, TRUE) . ' as recipient.');
-
- // Add the entry
- $listInstance->addEntry('unl', $unlData);
- } // END - foreach
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ObjectType registry
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ObjectTypeRegistry extends BaseRegistry implements Register {
- /**
- * Instance of this class
- */
- private static $registryInstance = NULL;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Singleton method, we really only need one instance of this class.
- *
- * @return $registryInstance Instance of this class
- */
- public static final function createObjectTypeRegistry () {
- // Is an instance there?
- if (is_null(self::$registryInstance)) {
- // Not yet, so create one
- self::$registryInstance = new ObjectTypeRegistry();
- } // END - if
-
- // Return the instance
- return self::$registryInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Socket registry
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 SocketRegistry extends BaseRegistry implements Register, RegisterableSocket {
- // Exception constants
- const SOCKET_NOT_REGISTERED = 0xd200;
-
- /**
- * Instance of this class
- */
- private static $registryInstance = NULL;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates a singleton instance of this registry class
- *
- * @return $registryInstance An instance of this class
- */
- public static final function createSocketRegistry () {
- // Is an instance there?
- if (is_null(self::$registryInstance)) {
- // Not yet, so create one
- self::$registryInstance = new SocketRegistry();
- } // END - if
-
- // Return the instance
- return self::$registryInstance;
- }
-
- /**
- * "Getter" to get a string respresentation for a key for the sub-registry
- * in this format: class:type:port
- *
- * @param $infoInstance An instance of a ShareableInfo class
- * @return $key A string representation of the socket for the registry
- */
- private function getSubRegistryKey (ShareableInfo $infoInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: infoInstance=' . $infoInstance->__toString() . ' - CALLED!');
-
- // Get address and port
- $address = $infoInstance->getAddress();
- $port = $infoInstance->getPort();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: address=' . $address . ',port=' . $port);
-
- // Get connection type and port number and add both together
- $key = sprintf('%s:%s:%s:%s',
- $infoInstance->__toString(),
- $infoInstance->getProtocolName(),
- $address,
- $port
- );
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ' - EXIT!');
-
- // Return resulting key
- return $key;
- }
-
- /**
- * "Getter" to get a string respresentation of the listener
- *
- * @param $infoInstance An instance of a ShareableInfo class
- * @return $key A string representation of the listener for the registry
- */
- private function getRegistryKeyFromInfo (ShareableInfo $infoInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',infoInstance=' . $infoInstance->__toString() . ' - CALLED!');
-
- // Get the key
- $key = $infoInstance->getProtocolName();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ' - EXIT!');
-
- // Return resulting key
- return $key;
- }
-
- /**
- * Checks whether the shared connection info is registered
- *
- * @param $infoInstance An instance of a ShareableInfo class
- * @return $isRegistered Whether the listener is registered
- */
- private function isInfoRegistered (ShareableInfo $infoInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ' - CALLED!');
-
- // Get the key
- $key = $this->getRegistryKeyFromInfo($infoInstance);
-
- // Determine it
- $isRegistered = $this->instanceExists($key);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
-
- // Return result
- return $isRegistered;
- }
-
- /**
- * Checks whether given socket resource is registered. If $socketResource is
- * FALSE only the instance will be checked.
- *
- * @param $infoInstance An instance of a ShareableInfo class
- * @param $socketResource A valid socket resource
- * @return $isRegistered Whether the given socket resource is registered
- */
- public function isSocketRegistered (ShareableInfo $infoInstance, $socketResource) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - CALLED!');
-
- // Default is not registered
- $isRegistered = FALSE;
-
- // First, check for the instance, there can be only once
- if ($this->isInfoRegistered($infoInstance)) {
- // That one is found so "get" a registry key from it
- $key = $this->getRegistryKeyFromInfo($infoInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...');
-
- // Get the registry
- $registryInstance = $this->getInstance($key);
-
- // "Get" a key for the socket
- $socketKey = $this->getSubRegistryKey($infoInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...');
-
- // Is it there?
- if ($registryInstance->instanceExists($socketKey)) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: Found instance for socketKey=' . $socketKey . ':' . $registryInstance->getInstance($socketKey));
-
- // Get the instance
- $registeredInstance = $registryInstance->getInstance($socketKey);
-
- // Is it SocketContainer and same socket?
- $isRegistered = (($registeredInstance instanceof SocketContainer) && ($registeredInstance->ifSocketResourceMatches($socketResource)));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: Final result: isRegistered(' . $socketResource . ')=' . intval($isRegistered));
- } // END - if
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
-
- // Return the result
- return $isRegistered;
- }
-
- /**
- * Registeres given socket for listener or throws an exception if it is already registered
- *
- * @param $infoInstance An instance of a ShareableInfo class
- * @param $socketResource A valid socket resource
- * @param $packageData Optional raw package data
- * @throws SocketAlreadyRegisteredException If the given socket is already registered
- * @return void
- */
- public function registerSocket (ShareableInfo $infoInstance, $socketResource, array $packageData = array()) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - CALLED!');
-
- // Is the socket already registered?
- if ($this->isSocketRegistered($infoInstance, $socketResource)) {
- // Throw the exception
- throw new SocketAlreadyRegisteredException(array($infoInstance, $socketResource), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
- } // END - if
-
- // Does the instance exist?
- if (!$this->isInfoRegistered($infoInstance)) {
- // No, not found so we create a sub registry (not needed to configure!)
- $registryInstance = SubRegistry::createSubRegistry();
-
- // Now we can create the sub-registry for this info
- $this->addInstance($this->getRegistryKeyFromInfo($infoInstance), $registryInstance);
- } else {
- // Get the sub-registry back
- $registryInstance = $this->getInstance($this->getRegistryKeyFromInfo($infoInstance));
- }
-
- // Get a key for sub-registries
- $socketKey = $this->getSubRegistryKey($infoInstance);
-
- // Get a socket container
- $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $infoInstance, $packageData));
-
- // We have a sub-registry, the socket key and the socket, now we need to put all together
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: socketKey=' . $socketKey . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - adding socket container instance ...');
- $registryInstance->addInstance($socketKey, $socketInstance);
- }
-
- /**
- * Getter for given listener's socket resource
- *
- * @param $listenerInstance An instance of a Listenable class
- * @return $socketResource A valid socket resource
- * @throws NoSocketRegisteredException If the requested socket is not registered
- */
- public function getRegisteredSocketResource (Listenable $listenerInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ' - CALLED!');
-
- // The socket must be registered before we can return it
- if (!$this->isInfoRegistered($listenerInstance)) {
- // Throw the exception
- throw new NoSocketRegisteredException ($listenerInstance, self::SOCKET_NOT_REGISTERED);
- } // END - if
-
- // Now get the key from the listener
- $key = $this->getRegistryKeyFromInfo($listenerInstance);
-
- // And get the registry
- $registryInstance = $this->getInstance($key);
-
- // Get a socket key
- $socketKey = $this->getSubRegistryKey($listenerInstance);
-
- // And the final socket resource
- $socketResource = $registryInstance->getInstance($socketKey)->getSocketResource();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!');
-
- // Return the resource
- return $socketResource;
- }
-
- /**
- * "Getter" for info instance from given package data
- *
- * @param $packageData Raw package data
- * @return $infoInstance An instance of a ShareableInfo class
- */
- public function getInfoInstanceFromPackageData (array $packageData) {
- // Init info instance
- $infoInstance = NULL;
- //* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
-
- // Get all keys and check them
- foreach ($this->getInstanceRegistry() as $key => $registryInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',registryInstance=' . $registryInstance->__toString());
-
- // This is always a SubRegistry instance
- foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString());
-
- // Is this a SocketContainer instance and is the address the same?
- if (($containerInstance instanceof SocketContainer) && ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]))) {
- // Debug die
- //* DEBUG-DIE: */ die(__METHOD__ . ': containerInstance=' . print_r($containerInstance, TRUE));
-
- // Get listener and helper instances
- $listenerInstance = $containerInstance->getListenerInstance();
- $helperInstance = $containerInstance->getHelperInstance();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
-
- // Is a listener or helper set?
- if ($listenerInstance instanceof Listenable) {
- // Found a listener, so get the info instance first
- $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($listenerInstance->getProtocolName(), 'helper');
-
- // Fill info instance with listener data
- $infoInstance->fillWithListenerInformation($listenerInstance);
- } elseif ($helperInstance instanceof ConnectionHelper) {
- // Found a helper, so get the info instance first
- $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($helperInstance->getProtocolName(), 'helper');
-
- // Helper is found
- $infoInstance->fillWithConnectionHelperInformation($helperInstance);
- } else {
- // Not supported state!
- $this->debugInstance('[' . __METHOD__ . ':' . __LINE__ . ']: Invalid state found, please report this to the developers with full debug infos.' . PHP_EOL);
- }
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',infoInstance[' . gettype($infoInstance) . ']=' . $infoInstance->__toString() . ' with protocol ' . $infoInstance->getProtocolName() . ' - FOUND!');
- break;
- } // END - if
- } // END - foreach
-
- // Is no longer NULL set?
- if (!is_null($infoInstance)) {
- // Then skip here, too
- break;
- } // END - if
- } // END - foreach
-
- // Return the info instance
- return $infoInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A command resolver for local (non-hubbed) web commands
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubConsoleCommandResolver extends BaseCommandResolver implements CommandResolver {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set prefix to "HubConsole"
- $this->setClassPrefix('hub_console');
- }
-
- /**
- * Creates an instance of a HubConsole command resolver with a given default command
- *
- * @param $commandName The default command we shall execute
- * @param $applicationInstance An instance of a manageable application helper class
- * @return $resolverInstance The prepared command resolver instance
- * @throws EmptyVariableException Thrown if default command is not set
- * @throws InvalidCommandException Thrown if default command is invalid
- */
- public static final function createHubConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) {
- // Create the new instance
- $resolverInstance = new HubConsoleCommandResolver();
-
- // Is the variable $commandName set and the command is valid?
- if (empty($commandName)) {
- // Then thrown an exception here
- throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif ($resolverInstance->isCommandValid($commandName) === FALSE) {
- // Invalid command found
- throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
- }
-
- // Set the application instance
- $resolverInstance->setApplicationInstance($applicationInstance);
-
- // Return the prepared instance
- return $resolverInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A command resolver for HTML commands
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2015 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 HubHtmlCommandResolver extends BaseCommandResolver implements CommandResolver {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set prefix to "HubHtml"
- $this->setClassPrefix('hub_html');
- }
-
- /**
- * Creates an instance of a HubHtml command resolver with a given default command
- *
- * @param $commandName The default command we shall execute
- * @param $applicationInstance An instance of a manageable application helper class
- * @return $resolverInstance The prepared command resolver instance
- * @throws EmptyVariableException Thrown if default command is not set
- * @throws InvalidCommandException Thrown if default command is invalid
- */
- public static final function createHubHtmlCommandResolver ($commandName, ManageableApplication $applicationInstance) {
- // Create the new instance
- $resolverInstance = new HubHtmlCommandResolver();
-
- // Is the variable $commandName set and the command is valid?
- if (empty($commandName)) {
- // Then thrown an exception here
- throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif ($resolverInstance->isCommandValid($commandName) === FALSE) {
- // Invalid command found
- throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
- }
-
- // Set the application instance
- $resolverInstance->setApplicationInstance($applicationInstance);
-
- // Return the prepared instance
- return $resolverInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A resolver for resolving controllers locally
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubConsoleControllerResolver extends BaseControllerResolver implements ControllerResolver {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set prefix to "HubConsole"
- $this->setClassPrefix('hub_console');
- }
-
- /**
- * Creates an instance of a resolver class with a given command
- *
- * @param $controllerName The controller we shall resolve
- * @param $applicationInstance An instance of a manageable application helper class
- * @return $resolverInstance The prepared controller resolver instance
- * @throws EmptyVariableException Thrown if default command is not set
- * @throws InvalidControllerException Thrown if default controller is invalid
- */
- public static final function createHubConsoleControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
- // Create the new instance
- $resolverInstance = new HubConsoleControllerResolver();
-
- // Is the variable $controllerName set and the command is valid?
- if (empty($controllerName)) {
- // Then thrown an exception here
- throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) {
- // Invalid command found
- throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- }
-
- // Set the application instance
- $resolverInstance->setApplicationInstance($applicationInstance);
-
- // Set command name
- $resolverInstance->setControllerName($controllerName);
-
- // Return the prepared instance
- return $resolverInstance;
- }
-
- /**
- * Resolves the default controller of the given command
- *
- * @return $controllerInstance A controller instance for the default
- * command
- * @throws InvalidControllerInstanceException Thrown if $controllerInstance
- * is invalid
- */
- public function resolveController () {
- // Init variables
- $controllerName = '';
- $controllerInstance = NULL;
-
- // Get the command name
- $controllerName = $this->getControllerName();
-
- // Get the command
- $controllerInstance = $this->loadController($controllerName);
-
- // And validate it
- if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
- // This command has an invalid instance!
- throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- } // END - if
-
- // Set last controller
- $this->setResolvedInstance($controllerInstance);
-
- // Return the maybe resolved instance
- return $controllerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A resolver for resolving controllers locally
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubHtmlControllerResolver extends BaseControllerResolver implements ControllerResolver {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set prefix to 'Html'
- $this->setClassPrefix('Html');
- }
-
- /**
- * Creates an instance of a resolver class with a given command
- *
- * @param $controllerName The controller we shall resolve
- * @param $applicationInstance An instance of a manageable application helper class
- * @return $resolverInstance The prepared controller resolver instance
- * @throws EmptyVariableException Thrown if default command is not set
- * @throws InvalidControllerException Thrown if default controller is invalid
- */
- public static final function createHubHtmlControllerResolver ($controllerName, ManageableApplication $applicationInstance) {
- // Create the new instance
- $resolverInstance = new HubHtmlControllerResolver();
-
- // Is the variable $controllerName set and the command is valid?
- if (empty($controllerName)) {
- // Then thrown an exception here
- throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) {
- // Invalid command found
- throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- }
-
- // Set the application instance
- $resolverInstance->setApplicationInstance($applicationInstance);
-
- // Set command name
- $resolverInstance->setControllerName($controllerName);
-
- // Return the prepared instance
- return $resolverInstance;
- }
-
- /**
- * Resolves the default controller of the given command
- *
- * @return $controllerInstance A controller instance for the default
- * command
- * @throws InvalidControllerInstanceException Thrown if $controllerInstance
- * is invalid
- */
- public function resolveController () {
- // Init variables
- $controllerName = '';
- $controllerInstance = NULL;
-
- // Get the command name
- $controllerName = $this->getControllerName();
-
- // Get the command
- $controllerInstance = $this->loadController($controllerName);
-
- // And validate it
- if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
- // This command has an invalid instance!
- throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
- } // END - if
-
- // Set last controller
- $this->setResolvedInstance($controllerInstance);
-
- // Return the maybe resolved instance
- return $controllerInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A !!! protocol resolver class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 !!!ProtocolResolver extends BaseProtocolResolver implements ProtocolResolver, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of a !!! protocol resolver
- *
- * @return $resolverInstance The prepared command resolver instance
- */
- public static final function create!!!ProtocolResolver () {
- // Create the new instance
- $resolverInstance = new !!!ProtocolResolver();
-
- // Return the prepared instance
- return $resolverInstance;
- }
-
- /**
- * Returns an instance of a LocateableNode class for a given NodeHelper
- * instance or null if it was not found.
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return $unlInstance An instance of a LocateableNode class
- * @todo 0% done
- */
- public function resolveUniversalNodeLocatorFromNodeHelper (NodeHelper $nodeInstance) {
- $this->partialStub('Please implement this method. nodeInstance=' . $nodeInstance->__toString());
- }
-
- /**
- * Returns the UNL as string from given configuration key.
- *
- * @param $configKey Configuration key for UNL address (valid: internal,external)
- * @return $unl Universal node locator
- * @todo 90% done
- */
- public function resolveUniversalNodeLocatorFromConfigKey ($configKey) {
- // Put all together
- $unl = sprintf('%s://%s',
- $this->getProtocolName(),
- $this->getConfigInstance()->getConfigEntry($configKey . '_address')
- );
-
- /*
- * And return it. Please note that e.g. a FaxProtocolResolver will
- * return a different UNL and therefore all protocol resolvers must do
- * it on their own way.
- */
- return $unl;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A generic protocol resolver class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseProtocolResolver extends BaseHubSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TCP protocol resolver class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolver, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set protocol type
- $this->setProtocolName('tcp');
- }
-
- /**
- * Creates an instance of a TCP protocol resolver
- *
- * @return $resolverInstance The prepared command resolver instance
- */
- public static final function createTcpProtocolResolver () {
- // Create the new instance
- $resolverInstance = new TcpProtocolResolver();
-
- // Return the prepared instance
- return $resolverInstance;
- }
-
- /**
- * Returns an instance of a LocateableNode class for a given NodeHelper
- * instance or null if it was not found.
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return $unlInstance An instance of a LocateableNode class
- * @todo 0% done
- */
- public function resolveUniversalNodeLocatorFromNodeHelper (NodeHelper $nodeInstance) {
- // Get search instance (to lookup database result)
- $searchInstance = $nodeInstance->getSearchInstance();
-
- // Make sure the in stance is valid
- assert($searchInstance instanceof SearchCriteria);
-
- // Refetch and rewind iterator
- $resultInstance = $nodeInstance->getWrapperInstance()->doSelectByCriteria($searchInstance);
-
- // Is the result valid?
- if ((!$resultInstance->valid()) || (!$resultInstance->next())) {
- // Node not found in database, this could mean that your database file is damaged.
- return NULL;
- } // END - if
-
- // Get current entry
- $current = $resultInstance->current();
-
- // This should always be the case, if not your database file might be damaged.
- assert($nodeInstance->getNodeId() == $current[NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID]);
-
- // Get UNL instance and handle over all data
- $unlInstance = ObjectFactory::createObjectByConfiguredName('universal_node_locator_class', array($current));
-
- // Return resolved instance
- return $unlInstance;
- }
-
- /**
- * Returns the UNL as string from given configuration key.
- *
- * @param $configKey Configuration key for UNL address (valid: internal,external)
- * @return $unl Universal node locator
- */
- public function resolveUniversalNodeLocatorFromConfigKey ($configKey) {
- // Get address
- $address = $this->getConfigInstance()->getConfigEntry($configKey . '_address');
-
- // Is the address empty?
- if (empty($address)) {
- // Okay, then find it
- switch ($configKey) {
- case 'external': // External IP
- $address = ConsoleTools::determineExternalAddress();
- break;
-
- case 'internal': // Internal IP
- $address = ConsoleTools::acquireSelfIPAddress();
- break;
- } // END - switch
- } // END - if
-
- // Put all together
- $unl = sprintf('%s://%s:%s',
- $this->getProtocolName(),
- $address,
- $this->getConfigInstance()->getConfigEntry('node_listen_port')
- );
-
- /*
- * And return it. Please note that e.g. a FaxProtocolResolver will
- * return a different UNL and therefore all protocol resolvers must do
- * it on their own way.
- */
- return $unl;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A generic state resolver class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseStateResolver extends BaseResolver {
- /**
- * Prefix for local, remote or other resolver
- */
- private $statePrefix = '';
-
- /**
- * Validated state name
- */
- private $stateName = '';
-
- /**
- * Protected constructor
- *
- * @param $className Name of the real class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Setter for state prefix
- *
- * @param $statePrefix Last validated statePrefix
- * @return void
- */
- protected final function setStatePrefix ($statePrefix) {
- $this->statePrefix = $statePrefix;
- }
-
- /**
- * Getter for state prefix
- *
- * @param $statePrefix Last validated statePrefix
- * @return void
- */
- protected final function getStatePrefix () {
- return $this->statePrefix;
- }
-
- /**
- * Setter for state name
- *
- * @param $stateName Last validated state name
- * @return void
- */
- protected final function setStateName ($stateName) {
- $this->stateName = $stateName;
- }
-
- /**
- * Getter for state name
- *
- * @return $stateName Last validated state name
- */
- public final function getStateName () {
- return $this->stateName;
- }
-
- /**
- * "Loads" a given state and instances it if not yet cached. If the
- * state was not found an UnresolveableStateException is thrown
- *
- * @param $stateName A state name we shall look for
- * @return $stateInstance A loaded state instance
- * @throws UnresolveableStateException Thrown if even the requested
- * state class is missing (bad!)
- */
- protected function loadState ($stateName) {
- // Init state instance
- $stateInstance = NULL;
-
- // Create state class name
- $className = $this->getStatePrefix() . '' . self::convertToClassName($stateName) . 'State';
-
- // ... and set it
- $this->setClassName($className);
-
- // Is this class loaded?
- if (!class_exists($this->getClassName())) {
- // Throw an exception here
- throw new UnresolveableStateException(array($this, $stateName), self::EXCEPTION_INVALID_STATE);
- } // END - if
-
- // Initialize the state
- $stateInstance = ObjectFactory::createObjectByName(
- $this->getClassName(),
- array($this)
- );
-
- // Return the result
- return $stateInstance;
- }
-
- /**
- * Checks whether the given state is valid
- *
- * @param $stateName The default state we shall execute
- * @return $isValid Whether the given state is valid
- * @throws EmptyVariableException Thrown if given state is not set
- * @throws DefaultStateException Thrown if default state was not found
- */
- public function isStateValid ($stateName) {
- // By default nothing shall be valid
- $isValid = FALSE;
-
- // Is a state set?
- if (empty($stateName)) {
- // Then thrown an exception here
- throw new EmptyVariableException(array($this, 'stateName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } // END - if
-
- // Create class name
- $className = $this->statePrefix . self::convertToClassName($stateName) . 'State';
-
- // Now, let us create the full name of the state class
- $this->setClassName($className);
-
- // Try it hard to get an state
- while ($isValid === FALSE) {
- // Is this class already loaded?
- if (class_exists($this->getClassName())) {
- // This class does exist. :-)
- $isValid = TRUE;
- } elseif ($this->getClassName() != $this->statePrefix . 'DefaultState') {
- // Set default state
- $this->setClassName($this->statePrefix . 'DefaultState');
- } else {
- // All is tried, give it up here
- throw new DefaultStateException($this, self::EXCEPTION_DEFAULT_STATE_GONE);
- }
- } // END - while
-
- // Return the result
- return $isValid;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A resolver for resolving peer states locally
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PeerStateResolver extends BaseStateResolver implements StateResolver {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set prefix to 'Peer'
- $this->setStatePrefix('Peer');
- }
-
- /**
- * Creates an instance of a resolver class with a given state
- *
- * @return $resolverInstance The prepared state resolver instance
- */
- public static final function createPeerStateResolver () {
- // Create the new instance
- $resolverInstance = new PeerStateResolver();
-
- // Return the prepared instance
- return $resolverInstance;
- }
-
- /**
- * Returns an state instance for a given raw package data and socket resource
- *
- * @param $helperInstance An instance of a ConnectionHelper class
- * @param $packageData Raw package data
- * @param $socketResource A valid socket resource
- * @return $stateInstance An instance of the resolved state
- * @throws InvalidSocketException If socketResource, even from getSocketResource() is no valid resource
- * @todo ~30% done
- */
- public static function resolveStateByPackage (ConnectionHelper $helperInstance, array $packageData, $socketResource) {
- // Get temporary resolver instance
- $resolverInstance = self::createPeerStateResolver();
-
- // Init state instance
- $stateInstance = NULL;
-
- // Is the socket resource valid?
- if (!is_resource($socketResource)) {
- // No, so get socket resource from helper
- $socketResource = $helperInstance->getSocketResource();
-
- // Still no socket resource?
- if (!is_resource($socketResource)) {
- // Then abort here with an exception (may happen after socket_shutdown())
- throw new InvalidSocketException(array($helperInstance, $socketResource, 'unknown', 'unknown'), BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
- } // END - if
-
- // Get error code from it
- $errorCode = socket_last_error($socketResource);
-
- // Translate the error code to an own name
- $errorCode = $helperInstance->translateSocketErrorCodeToName($errorCode);
-
- // Create a state instance based on $errorCode. This factory does the hard work for us
- $stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageData, $socketResource, $errorCode);
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? scanner class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Scanner extends BaseScanner implements Scanner, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $scannerInstance An instance of a Scanner class
- */
- public final static function create???Scanner () {
- // Get new instance
- $scannerInstance = new ???Scanner();
-
- // Return the prepared instance
- return $scannerInstance;
- }
-
- /**
- * Runs the scanner (please no loops here)
- *
- * @return void
- * @todo 0% done
- */
- public function execute () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general Scanner class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 BaseScanner extends BaseHubSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? scanner class for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Crawler???Scanner extends BaseScanner implements Scanner, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $scannerInstance An instance of a Scanner class
- */
- public final static function createCrawler???Scanner () {
- // Get new instance
- $scannerInstance = new Crawler???Scanner();
-
- // Return the prepared instance
- return $scannerInstance;
- }
-
- /**
- * Runs the scanner (please no loops here)
- *
- * @return void
- * @todo 0% done
- */
- public function execute () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A UploadedList scanner class for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerUploadedListScanner extends BaseScanner implements Scanner, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $scannerInstance An instance of a Scanner class
- */
- public final static function createCrawlerUploadedListScanner () {
- // Get new instance
- $scannerInstance = new CrawlerUploadedListScanner();
-
- // Return the prepared instance
- return $scannerInstance;
- }
-
- /**
- * Runs the scanner (please no loops here)
- *
- * @return void
- * @todo 0% done
- */
- public function execute () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? source class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Source extends BaseSource implements Source!!! {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $sourceInstance An instance of a Source class
- */
- public final static function create???Source () {
- // Get new instance
- $sourceInstance = new ???Source();
-
- // Return the prepared instance
- return $sourceInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general Source class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseSource extends BaseHubSystem {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general URL source class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseUrlSource extends BaseSource {
- // Stack name for all URLs
- const STACKER_NAME_URLS = 'urls';
-
- // Array elements for CSV data array
- const CRAWL_JOB_ARRAY_START_URL = 'start_url';
- const CRAWL_JOB_ARRAY_DEPTH = 'start_depth';
- const CRAWL_JOB_ARRAY_EXTERNAL_DEPTH = 'external_depth';
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Initalizes this source
- *
- * @param $prefix Prefix for this source
- * @param $sourceName Name of this source
- * @return void
- */
- protected function initSource ($prefix, $sourceName) {
- // Use another object factory
- $stackInstance = FileStackFactory::createFileStackInstance($prefix . '_url', $sourceName);
-
- // Set the stack here
- $this->setStackInstance($stackInstance);
- }
-
- /**
- * Determines whether the stack 'urls' is empty.
- *
- * @return $isEmpty Whether the stack 'urls' is empty.
- */
- public function isUrlStackEmpty () {
- // Determine it
- $isEmpty = $this->getStackInstance()->isStackEmpty(self::STACKER_NAME_URLS);
-
- // Return result
- return $isEmpty;
- }
-
- /**
- * Enriches the given associative array with more data, now at least 2
- * elements are required:
- *
- * 'start_url' - Starting URL
- * 'start_depth' - Crawl depth for starting URL
- *
- * @param $crawlData Array with partial data for being queued
- * @return void
- * @todo ~10% done
- */
- protected function enrichCrawlerQueueData (array &$crawlData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: crawlData()=' . count($crawlData) . ' - CALLED!');
-
- // Check for minimum array elements
- assert(isset($crawlData[self::CRAWL_JOB_ARRAY_START_URL]));
- assert(isset($crawlData[self::CRAWL_JOB_ARRAY_DEPTH]));
-
- // @TODO Add more elements
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Enqueues given crawler array in assigned file-based stack
- *
- * @param $crawlData Array with partial data for being queued
- * @return void
- */
- protected function enqueueInFileStack (array $crawlData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: crawlData()=' . count($crawlData) . ' - CALLED!');
-
- // Get the stack instance and enqueue it
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_URLS, $crawlData);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A TestUnit source class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TestUnitSource extends BaseSource implements UnitSource, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $sourceInstance An instance of a Source class
- */
- public final static function createTestUnitSource () {
- // Get new instance
- $sourceInstance = new TestUnitSource();
-
- // Create a RNG instance and set it in this class
- $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
- $sourceInstance->setRngInstance($rngInstance);
-
- // And also a crypto instance (for our encrypted messages)
- $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
- $sourceInstance->setCryptoInstance($cryptoInstance);
-
- // Return the prepared instance
- return $sourceInstance;
- }
-
- /**
- * Generates an encrypted random message
- *
- * @return $encryptedMessage The encrypted random message
- */
- public function generateMessageFromSource () {
- // Get a very secret message by encoding and random string with BASE64
- $secretMessage = base64_encode($this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_message_length')));
-
- // Get a random, secret key
- $secretKey = $this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('test_unit_random_secret_key_length') / 8);
-
- // Now encrypt the message with our key and a good (strong) cipher
- $encryptedMessage = base64_encode($this->getCryptoInstance()->encryptString($secretMessage, $secretKey));
-
- // Return it
- return $encryptedMessage;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? URL source class for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Crawler???UrlSource extends BaseUrlSource implements UrlSource, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $sourceInstance An instance of a Source class
- */
- public final static function createCrawler???UrlSource () {
- // Get new instance
- $sourceInstance = new Crawler???UrlSource();
-
- // Init source
- $sourceInstance->initSource('crawler', '!!!');
-
- // Return the prepared instance
- return $sourceInstance;
- }
-
- /**
- * Processes entries in the stack.
- *
- * @return void
- * @todo ~ 10% done
- */
- public function processStack () {
- // Does the stack have some entries left?
- if ($this->isUrlStackEmpty()) {
- // Nothing to handle here
- return;
- } // END - if
-
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A FoundRss URL source class for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerFoundRssUrlSource extends BaseUrlSource implements UrlSource, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $sourceInstance An instance of a Source class
- */
- public final static function createCrawlerFoundRssUrlSource () {
- // Get new instance
- $sourceInstance = new CrawlerFoundRssUrlSource();
-
- // Init source
- $sourceInstance->initSource('crawler', 'found_rss');
-
- // Return the prepared instance
- return $sourceInstance;
- }
-
- /**
- * Fills the URL stack with new entries from source
- *
- * @return void
- * @todo 0% done
- */
- public function fillUrlStack () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? URL source class for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerLocalStartUrlSource extends BaseUrlSource implements UrlSource, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $sourceInstance An instance of a Source class
- */
- public final static function createCrawlerLocalStartUrlSource () {
- // Get new instance
- $sourceInstance = new CrawlerLocalStartUrlSource();
-
- // Init source
- $sourceInstance->initSource('crawler', 'local_start');
-
- // Return the prepared instance
- return $sourceInstance;
- }
-
- /**
- * Fills the URL stack with new entries from source
- *
- * @return void
- * @todo 0% done
- */
- public function fillUrlStack () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A RssStart URL source class for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerRssStartUrlSource extends BaseUrlSource implements UrlSource, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $sourceInstance An instance of a Source class
- */
- public final static function createCrawlerRssStartUrlSource () {
- // Get new instance
- $sourceInstance = new CrawlerRssStartUrlSource();
-
- // Init source
- $sourceInstance->initSource('crawler', 'rss_start');
-
- // Return the prepared instance
- return $sourceInstance;
- }
-
- /**
- * Fills the URL stack with new entries from source
- *
- * @return void
- * @todo 0% done
- */
- public function fillUrlStack () {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A UploadedList URL source class for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerUploadedListUrlSource extends BaseUrlSource implements UrlSource, Registerable {
- /**
- * Stack name for a CSV file
- */
- const STACK_NAME_CSV_FILE = 'csv_file';
-
- /**
- * Stack name for a CSV entry
- */
- const STACK_NAME_CSV_ENTRY = 'csv_entry';
-
- /**
- * Size of crawl (CSV) entry which is an indexed array:
- *
- * 0 = URL to crawl
- * 1 = Crawl depth of URL
- * 2 = Crawl depth of linked URLs (same other host only)
- */
- const CRAWL_ENTRY_SIZE = 3;
-
- /**
- * "Cached" CSV path
- */
- private $csvFilePath = '';
-
- /**
- * Last CSV file instance
- */
- private $lastCsvFileInstance = NULL;
-
- /**
- * Stack for pushing data from this clas to another
- */
- private $stackSourceInstance = NULL;
-
- /**
- * "Imported" CSV files
- */
- private $csvFileImported = array();
-
- /**
- * "Cached" separator for columns
- */
- private $columnSeparator = '';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // "Cache" CSV path for faster usage
- $this->csvFilePath = $this->getConfigInstance()->getConfigEntry('base_path') . '/' . $this->getConfigInstance()->getConfigEntry('crawler_csv_file_path');
-
- // Initialize directory instance
- $directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($this->csvFilePath));
-
- // Set it here
- $this->setDirectoryInstance($directoryInstance);
-
- // Init stack instance
- $this->stackSourceInstance = ObjectFactory::createObjectByConfiguredName('crawler_uploaded_list_url_source_stack_class');
-
- // Init stacks
- $this->getStackSourceInstance()->initStack(self::STACK_NAME_CSV_FILE);
- $this->getStackSourceInstance()->initStack(self::STACK_NAME_CSV_ENTRY);
-
- // "Cache" column separator
- $this->columnSeparator = $this->getConfigInstance()->getConfigEntry('crawler_url_list_column_separator');
- }
-
- /**
- * Checks whether a CSV file is found in configured path
- *
- * @return $isFound Whether a CSV file is found
- */
- private function isCsvFileFound () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Is it valid?
- if (!$this->getDirectoryInstance()->getDirectoryIteratorInstance()->valid()) {
- // Rewind to start
- $this->getDirectoryInstance()->getDirectoryIteratorInstance()->rewind();
- } // END - if
-
- // Read next entry
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: this->csvFileImported=' . print_r($this->csvFileImported, TRUE));
- $directoryEntry = $this->getDirectoryInstance()->readDirectoryExcept(array_merge(array('.htaccess', '.', '..'), $this->csvFileImported));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE[' . __METHOD__ . ':' . __LINE__ . '] directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry);
-
- // Is it empty or wrong file extension?
- if ((empty($directoryEntry)) || (substr($directoryEntry, -4, 4) != '.csv')) {
- // Skip further processing
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE[' . __METHOD__ . ':' . __LINE__ . '] directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry . ' - SKIPPED!');
- return FALSE;
- } // END - if
-
- // Initialize CSV file instance
- $this->lastCsvFileInstance = ObjectFactory::createObjectByConfiguredName('csv_input_file_class', array($this->csvFilePath . '/' . $directoryEntry));
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . '] directoryEntry(' . strlen($directoryEntry) . ')=' . $directoryEntry . ' - Instance created - EXIT!');
-
- // Found an entry
- return TRUE;
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $sourceInstance An instance of a Source class
- */
- public final static function createCrawlerUploadedListUrlSource () {
- // Get new instance
- $sourceInstance = new CrawlerUploadedListUrlSource();
-
- // Init source
- $sourceInstance->initSource('crawler', 'uploaded_list');
-
- // Return the prepared instance
- return $sourceInstance;
- }
-
- /**
- * Enriches and saves the given CSV entry (array) in the assigned
- * file-based stack. To such entry a lot more informations are added, such
- * as which files shall be crawled and many more.
- *
- * @param $csvData Array with data from a CSV file
- * @return void
- */
- private function saveCsvDataInCrawlerQueue (array $csvData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvData()=' . count($csvData) . ' - CALLED!');
-
- // The array must have a fixed amount of elements, later enhancements may accept more
- assert(count($csvData) == self::CRAWL_ENTRY_SIZE);
-
- /*
- * First converted the indexed array into an assoziative array. Don't
- * forget to expand this array as well when you want to add another
- * column to the CSV file.
- */
- $csvArray = array(
- self::CRAWL_JOB_ARRAY_START_URL => $csvData[0],
- self::CRAWL_JOB_ARRAY_DEPTH => $csvData[1],
- self::CRAWL_JOB_ARRAY_EXTERNAL_DEPTH => $csvData[2]
- );
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvArray()=' . count($csvArray) . ' - BEFORE!');
-
- // Then add more data to it
- $this->enrichCrawlerQueueData($csvArray);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvArray()=' . count($csvArray) . ' - AFTER!');
-
- /*
- * Then enqueue it in the file stack. The local crawler "task" will
- * then pick this up.
- */
- $this->enqueueInFileStack($csvArray);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Checks whether a CSV file has been loaded (added to the stack)
- *
- * @return $isAdded Whether a CSV file has been loaded
- */
- private function isCsvFileAdded () {
- // Check whether the stacker is not empty
- $isAdded = (($this->getStackSourceInstance()->isStackInitialized(self::STACK_NAME_CSV_FILE)) && (!$this->getStackSourceInstance()->isStackEmpty(self::STACK_NAME_CSV_FILE)));
-
- // Return the result
- return $isAdded;
- }
-
- /**
- * Checks whether a CSV entry has been added to the stack
- *
- * @return $isAdded Whether a CSV entry has been added
- */
- private function isCsvEntryAdded () {
- // Check whether the stacker is not empty
- $isAdded = (($this->getStackSourceInstance()->isStackInitialized(self::STACK_NAME_CSV_ENTRY)) && (!$this->getStackSourceInstance()->isStackEmpty(self::STACK_NAME_CSV_ENTRY)));
-
- // Return the result
- return $isAdded;
- }
-
- /**
- * Initializes the import of the CSV file which is being processed by other task
- *
- * @return void
- * @throws NullPointerException If lastCsvFileInstance is not set
- */
- private function addCsvFile () {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Is the instance set?
- if (is_null($this->lastCsvFileInstance)) {
- // This should not happen
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } // END - if
-
- // Stack this file
- $this->getStackSourceInstance()->pushNamed(self::STACK_NAME_CSV_FILE, $this->lastCsvFileInstance);
-
- // ... and mark it as "imported"
- array_push($this->csvFileImported, basename($this->lastCsvFileInstance->getFileName()));
-
- // ... and finally NULL it (to save some RAM)
- $this->lastCsvFileInstance = NULL;
-
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Parses the next stacked CSV file by reading only one line from it. Then
- * the read line is being validated and if found good being feed to the next
- * stack. The file is removed from stack only if it has been fully parsed.
- *
- * @return void
- */
- private function parseCsvFile () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Get next entry
- $csvFileInstance = $this->getStackSourceInstance()->popNamed(self::STACK_NAME_CSV_FILE);
-
- // Read full "CSV line"
- $csvData = $csvFileInstance->readCsvFileLine($this->columnSeparator);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvData[' . gettype($csvData) . ']=' . print_r($csvData, TRUE));
-
- // Expect always an array
- assert(is_array($csvData));
-
- // Is the array empty?
- if (count($csvData) == 0) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: File ' . $csvFileInstance->getFileName() . ' has been fully read.');
-
- // Try to close it by actually unsetting (destructing) it
- unset($csvFileInstance);
-
- // This file as been fully read, so don't push it back on stack.
- return;
- } // END - if
-
- // ... with a fixed amount of elements, later enhancements may accept more
- assert(count($csvData) == self::CRAWL_ENTRY_SIZE);
-
- /*
- * Push the file back on stack as it may contain more entries. This way
- * all files got rotated on stack which may improve crawler performance.
- */
- $this->getStackSourceInstance()->pushNamed(self::STACK_NAME_CSV_FILE, $csvFileInstance);
-
- // Push array on next stack
- $this->getStackSourceInstance()->pushNamed(self::STACK_NAME_CSV_ENTRY, $csvData);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Parses the next stacked CSV entry.
- *
- * @return void
- */
- private function parseCsvEntry () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Pop it from stack
- $csvData = $this->getStackSourceInstance()->popNamed(self::STACK_NAME_CSV_ENTRY);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: csvData[' . gettype($csvData) . ']=' . print_r($csvData, TRUE));
-
- // It must have a fixed amount of elements (see method parseCsvFile() for details)
- assert(count($csvData) == self::CRAWL_ENTRY_SIZE);
-
- // Save it in crawler queue (which will enrich it with way more informations
- $this->saveCsvDataInCrawlerQueue($csvData);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRAWLER-SOURCE [' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- }
-
- /**
- * Getter for stackSourceInstance variable
- *
- * @return $stackSourceInstance An instance of an additional stack
- */
- public final function getStackSourceInstance () {
- return $this->stackSourceInstance;
- }
-
- /**
- * Fills the URL stack with new entries from source
- *
- * @return void
- * @todo ~40% done
- */
- public function fillUrlStack () {
- // Does the stack have some entries left?
- if ($this->isCsvEntryAdded()) {
- /*
- * A CSV file has been found and "imported" (added to stack). Now
- * the file can be read line by line and checked every one of it.
- */
- $this->parseCsvEntry();
- } elseif ($this->isCsvFileAdded()) {
- /*
- * A CSV file has been found and "imported" (added to stack). Now
- * the file can be read line by line and checked every one of it.
- */
- $this->parseCsvFile();
- } elseif ($this->isCsvFileFound()) {
- /*
- * A file containing an URL list is found. Please note the format is
- * CSV-like as you may wish to provide meta data such as crawl
- * depth, handling of 3rd-party URLs and such.
- */
- $this->addCsvFile();
- }
-
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A active communicator state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CommunicatorActiveState extends BaseCommunicatorState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructo
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('active');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $communicatorInstance An instance of a Communicator class
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createCommunicatorActiveState (Communicator $communicatorInstance) {
- // Get new instance
- $stateInstance = new CommunicatorActiveState();
-
- // Set the communicator instance
- $stateInstance->setCommunicatorInstance($communicatorInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? communicator state class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014, 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Communicator???State extends BaseCommunicatorState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('!!!');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $communicatorInstance An instance of a Communicator class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createCommunicator???State (Communicator $communicatorInstance) {
- // Get new instance
- $stateInstance = new Communicator???State();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('COMMUNICATOR-STATE: Has changed from ' . $communicatorInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the communicator instance
- $stateInstance->setCommunicatorInstance($communicatorInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general communicator state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014, 2015 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 BaseCommunicatorState extends BaseState {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Validates whether the state is 'active' or throws an exception if
- * it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'active'
- */
- public function validateCommunicatorStateIsActive () {
- // Just compare it...
- if (!$this instanceof CommunicatorActiveState) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A init communicator state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CommunicatorInitState extends BaseCommunicatorState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructo
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('init');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $communicatorInstance An instance of a Communicator class
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createCommunicatorInitState (Communicator $communicatorInstance) {
- // Get new instance
- $stateInstance = new CommunicatorInitState();
-
- // Set the communicator instance
- $stateInstance->setCommunicatorInstance($communicatorInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- * @todo 0% done?
- */
- public function executeState (Executor $executorInstance) {
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A active crawler state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CrawlerActiveState extends BaseCrawlerState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructo
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('active');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $crawlerInstance An instance of a Crawler class
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createCrawlerActiveState () {
- // Get new instance
- $stateInstance = new CrawlerActiveState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- * @todo 0% done
- */
- public function executeState (Executor $executorInstance) {
- $this->partialStub('Unfinished method, executorInstance=' . $executorInstance->__toString());
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-
- /**
- * State change if the communicator has fully initialized.
- *
- * @return void
- * @todo ~30% done
- */
- public function communicatorHasInitialized () {
- // Please implement
- $this->partialStub('Unfinished method.');
-
- // Change state to 'active'
- CrawlerStateFactory::createCrawlerStateInstanceByName('active');
- }
+++ /dev/null
-<?php
-/**
- * A booting crawler state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CrawlerBootingState extends BaseCrawlerState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructo
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('booting');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createCrawlerBootingState () {
- // Get new instance
- $stateInstance = new CrawlerBootingState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- * @todo 0% done
- */
- public function executeState (Executor $executorInstance) {
- $this->partialStub('Unfinished method, executorInstance=' . $executorInstance->__toString());
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? crawler state class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Crawler???State extends BaseCrawlerState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('!!!');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $crawlerInstance An instance of a Crawler class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createCrawler???State (Crawler $crawlerInstance) {
- // Get new instance
- $stateInstance = new Crawler???State();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('COMMUNICATOR-STATE: Has changed from ' . $crawlerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the crawler instance
- $stateInstance->setCrawlerInstance($crawlerInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general crawler state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler 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 BaseCrawlerState extends BaseState {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Validates whether the state is 'active' or throws an exception if
- * it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'active'
- */
- public function validateCrawlerStateIsActive () {
- // Just compare it...
- if (!$this instanceof CrawlerActiveState) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A init crawler state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 CrawlerInitState extends BaseCrawlerState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructo
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('init');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createCrawlerInitState () {
- // Get new instance
- $stateInstance = new CrawlerInitState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- */
- public function executeState (Executor $executorInstance) {
- // Initialize the executor (can be a Communicator instance)
- $executorInstance->initExecutor($this);
- }
-
- /**
- * State change if the communicator has fully initialized.
- *
- * @return void
- * @todo ~30% done
- */
- public function communicatorHasInitialized () {
- // Please implement
- $this->partialStub('Unfinished method.');
-
- // Change state to 'booting'
- CrawlerStateFactory::createCrawlerStateInstanceByName('booting');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? cruncher state class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Cruncher Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Cruncher???State extends BaseCruncherState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('!!!');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $cruncherInstance An instance of a CruncherHelper class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createCruncher???State (CruncherHelper $cruncherInstance) {
- // Get new instance
- $stateInstance = new Cruncher???State();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER-STATE: Has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the cruncher instance
- $stateInstance->setCruncherInstance($cruncherInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- */
- public function executeState (Executor $executorInstance) {
- $this->partialStub('This state needs implementation. executorInstance=' . $executorInstance->__toString());
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general cruncher state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 BaseCruncherState extends BaseState {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Validates whether the state is 'active' or throws an exception if
- * it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'active'
- */
- public function validateCruncherStateIsActive () {
- // Just compare it...
- if (!$this instanceof CruncherActiveState) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-
- /**
- * Checks if this state is 'virgin'
- *
- * @return $isVirgin Whether this state is 'virgin'
- */
- public function isCruncherStateVirgin () {
- // Just compare it...
- return ($this instanceof CruncherVirginState);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Init cruncher state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherInitState extends BaseCruncherState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('init');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createCruncherInitState () {
- // Get new instance
- $stateInstance = new CruncherInitState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- */
- public function executeState (Executor $executorInstance) {
- // Initialize the unit production to maybe become 'virgin' or 'active' if work/test units are there
- $executorInstance->initUnitProduction($this);
- }
-
- /**
- * An encrypted message has been generated so we change the state to
- * 'virgin'.
- *
- * @return void
- */
- public function encryptedMessageGenerated () {
- // Change the state now to 'virgin'
- CruncherStateFactory::createCruncherStateInstanceByName('virgin');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Virgin cruncher state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherVirginState extends BaseCruncherState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('virgin');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createCruncherVirginState () {
- // Get new instance
- $stateInstance = new CruncherVirginState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- */
- public function executeState (Executor $executorInstance) {
- // Produce some keys now
- $executorInstance->produceKeys($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Active dht state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtActiveState extends BaseDhtState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('active');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $dhtInstance An instance of a Distributable class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createDhtActiveState (Distributable $dhtInstance) {
- // Get new instance
- $stateInstance = new DhtActiveState();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE[' . __METHOD__ . ':' . __LINE__ . ']: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the dht instance
- $stateInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Booting dht state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtBootingState extends BaseDhtState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('booting');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $dhtInstance An instance of a Distributable class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createDhtBootingState (Distributable $dhtInstance) {
- // Get new instance
- $stateInstance = new DhtBootingState();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE[' . __METHOD__ . ':' . __LINE__ . ']: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the dht instance
- $stateInstance->setDhtInstance($dhtInstance);
-
- // Get node instance and enable DHT bootstrap requests
- NodeObjectFactory::createNodeInstance()->enableAcceptDhtBootstrap();
-
- // Update DHT node info as well
- $dhtInstance->enableAcceptDhtBootstrap();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? dht state class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Dht???State extends BaseDhtState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('!!!');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $dhtInstance An instance of a Distributable class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createDht???State (Distributable $dhtInstance) {
- // Get new instance
- $stateInstance = new Dht???State();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the dht instance
- $stateInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general DHT state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Create generic DHT interface
- *
- * 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 BaseDhtState extends BaseState {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Validates whether the DHT state is 'virgin' or throws an exception if it
- * is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'virgin'
- */
- public function validateDhtStateIsVirginOrInit () {
- // Just compare it...
- if ((!$this instanceof DhtVirginState) && (!$this instanceof DhtInitState)) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-
- /**
- * Checks whether the DHT's state is 'booting' by comparing it with the
- * state's class name.
- *
- * @return $isBooting Whether this DHT's state is 'booting'
- */
- public function ifDhtIsBooting () {
- // Check state
- $isBooting = ($this instanceof DhtBootingState);
-
- // Return status
- return $isBooting;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Init dht state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtInitState extends BaseDhtState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('init');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $dhtInstance An instance of a Distributable class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createDhtInitState (Distributable $dhtInstance) {
- // Get new instance
- $stateInstance = new DhtInitState();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE[' . __METHOD__ . ':' . __LINE__ . ']: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the dht instance
- $stateInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * The DHT has been initialized. This means that the state can be changed
- * to the next one: virgin.
- *
- * @return void
- */
- public function dhtHasInitialized () {
- // Create a new instance
- DhtStateFactory::createDhtStateInstanceByName('virgin', $this->getDhtInstance());
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Virgin dht state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 DhtVirginState extends BaseDhtState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('virgin');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $dhtInstance An instance of a Distributable class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createDhtVirginState (Distributable $dhtInstance) {
- // Get new instance
- $stateInstance = new DhtVirginState();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE[' . __METHOD__ . ':' . __LINE__ . ']: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the dht instance
- $stateInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Called when the DHT is booting. This means that the bootstrap message
- * has been queued.
- *
- * @return void
- */
- public function dhtIsBooting () {
- // Get new instance and set it
- DhtStateFactory::createDhtStateInstanceByName('booting', $this->getDhtInstance());
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Booting miner state class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 MinerBootingState extends BaseMinerState implements Stateable {
- /**
- * Array of booted producers
- */
- private $bootedProducer = array();
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('booting');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createMinerBootingState () {
- // Get new instance
- $stateInstance = new MinerBootingState();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Has changed from ' . $minerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- */
- public function executeState (Executor $executorInstance) {
- // Has this executor (producer) run?
- if (isset($this->bootedProducer[$executorInstance->__toString()])) {
- // Then silently skip this
- return;
- } // END - if
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Calling prepareBlockProduction() on ' . $executorInstance->__toString() . ' ...');
-
- // Now prepare the unit production to maybe become 'virgin' or 'active' if work/test units are there
- $executorInstance->prepareBlockProduction($this);
-
- // Mark producer as booted
- $this->bootedProducer[$executorInstance->__toString()] = TRUE;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general miner state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 BaseMinerState extends BaseState {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Validates whether the state is 'active' or throws an exception if
- * it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'active'
- */
- public function validateMinerStateIsActive () {
- // Just compare it...
- if (!$this instanceof MinerActiveState) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-
- /**
- * Validates whether the state is 'init' or throws an exception if
- * it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'init'
- */
- public function validateMinerStateIsInit () {
- // Just compare it...
- if (!$this instanceof MinerInitState) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-
- /**
- * Validates whether the state is 'booting' or throws an exception if
- * it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'booting'
- */
- public function validateMinerStateIsBooting () {
- // Just compare it...
- if (!$this instanceof MinerBootingState) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-
- /**
- * Checks if this state is 'virgin'
- *
- * @return $isVirgin Whether this state is 'virgin'
- */
- public function isMinerStateVirgin () {
- // Just compare it...
- return ($this instanceof MinerVirginState);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? miner state class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Miner???State extends BaseMinerState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('!!!');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $minerInstance An instance of a MinerHelper class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createMiner???State (MinerHelper $minerInstance) {
- // Get new instance
- $stateInstance = new Miner???State();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Has changed from ' . $minerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the miner instance
- $stateInstance->setMinerInstance($minerInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- */
- public function executeState (Executor $executorInstance) {
- $this->partialStub('This state needs implementation. executorInstance=' . $executorInstance->__toString());
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Init miner state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Miner 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 MinerInitState extends BaseMinerState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('init');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createMinerInitState () {
- // Get new instance
- $stateInstance = new MinerInitState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- * @todo 0% done?
- */
- public function executeState (Executor $executorInstance) {
- }
-
- /**
- * An encrypted message has been generated so we change the state to
- * 'virgin'.
- *
- * @return void
- */
- public function encryptedMessageGenerated () {
- // Change the state now to 'virgin'
- MinerStateFactory::createMinerStateInstanceByName('virgin');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Virgin miner state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerVirginState extends BaseMinerState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('virgin');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createMinerVirginState () {
- // Get new instance
- $stateInstance = new MinerVirginState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Executes the state with given Executor instance
- *
- * @param $executorInstance An instance of a Executor class
- * @return void
- */
- public function executeState (Executor $executorInstance) {
- // Produce some keys now
- $executorInstance->produceKeys($this);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An active node state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeActiveState extends BaseNodeState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('active');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createNodeActiveState () {
- // Get new instance
- $stateInstance = new NodeActiveState();
-
- // Get node instance and set 'active' flag
- NodeObjectFactory::createNodeInstance()->enableIsActive();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * State change for if the node got announced to it's upper hubs
- *
- * @return void
- */
- public function nodeAnnouncingToUpperHubs () {
- // Create the new state instance
- NodeStateFactory::createNodeStateInstanceByName('announcing');
- }
-
- /**
- * State change for if the node has just connected to itself and
- * node/session id are both equal. The self-connect means that
- * the node possibly reachable from outside. This may require
- * confirmation by other peers.
- *
- * @return void
- * @todo We might want to move some calls to this method to fill it with life
- */
- public function nodeHasSelfConnected () {
- // Create the new state instance
- NodeStateFactory::createNodeStateInstanceByName('reachable');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A AnnouncementCompleted node state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeAnnouncementCompletedState extends BaseNodeState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('announcement_completed');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createNodeAnnouncementCompletedState () {
- // Get new instance
- $stateInstance = new NodeAnnouncementCompletedState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [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 - 2015 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
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createNodeAnnouncingState () {
- // Get new instance
- $stateInstance = new NodeAnnouncingState();
-
- // 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');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? node state class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Node???State extends BaseNodeState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('!!!');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createNode???State (NodeHelper $nodeInstance) {
- // Get new instance
- $stateInstance = new Node???State();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
- // Set the node instance
- $stateInstance->setNodeInstance($nodeInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general node state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseNodeState extends BaseState {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Validates whether the state is 'active' or throws an exception if
- * it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'active'
- */
- public function validateNodeStateIsActive () {
- // Just compare it...
- if (!$this instanceof NodeActiveState) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-
- /**
- * Validates whether the state is 'active' or 'announcing' or throws an
- * exception if it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'active' and not 'announcing'
- */
- public function validateNodeStateIsActiveOrAnnouncing () {
- // Just compare it...
- if ((!$this instanceof NodeActiveState) && (!$this instanceof NodeAnnouncingState)) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-
- /**
- * Validates whether the state is 'active' or 'reachable' or throws an
- * exception if it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'active' and not 'reachable'
- */
- public function validateNodeStateIsActiveOrReachable () {
- // Just compare it...
- if ((!$this instanceof NodeActiveState) && (!$this instanceof NodeReachableState)) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-
- /**
- * Validates if the state is 'announcement_completed' or throws an
- * exception if it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'active' and not 'announcing'
- */
- public function validateNodeStateIsAnnouncementCompleted () {
- // Just compare it...
- if (!$this instanceof NodeAnnouncementCompletedState) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A init node state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeInitState extends BaseNodeState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructo
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('init');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createNodeInitState () {
- // Get new instance
- $stateInstance = new NodeInitState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * State change for if the node has just generated a session id. This makes
- * nodes with current state 'init' now 'virgin'.
- *
- * @return void
- * @todo We might want to move some calls to this method to fill it with life
- */
- public function nodeGeneratedSessionId () {
- // Create the new state instance
- NodeStateFactory::createNodeStateInstanceByName('virgin');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Reachable node state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeReachableState extends BaseNodeState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('reachable');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public final static function createNodeReachableState () {
- // Get new instance
- $stateInstance = new NodeReachableState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * State change for if the node got announced to it's upper hubs
- *
- * @return void
- */
- public function nodeAnnouncingToUpperHubs () {
- // Create the new state instance
- NodeStateFactory::createNodeStateInstanceByName('announcing');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A virgin node state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeVirginState extends BaseNodeState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('virgin');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createNodeVirginState () {
- // Get new instance
- $stateInstance = new NodeVirginState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Change the state to 'active' when the hub has initialized all
- * listeners, tasks, queues, etc. An active hub does not imply that it
- * can be reached from outside so we have to deal with that state with
- * yet another state class.
- *
- * @return void
- */
- public function nodeIsActivated () {
- // Create the new state instance
- NodeStateFactory::createNodeStateInstanceByName('active');
- }
-
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? peer state class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???PeerState extends BasePeerState implements PeerStateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_!!!);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a PeerStateable class
- */
- public final static function create???PeerState () {
- // Get new instance
- $stateInstance = new ???PeerState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general peer state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BasePeerState extends BaseState {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Validates whether the state is 'connected' or throws an exception if
- * it is every other state.
- *
- * @return void
- * @throws UnexpectedStateException If the state is not 'connected'
- */
- public function validatePeerStateConnected () {
- // Just compare it...
- if (!$this->isPeerStateConnected()) {
- // Throw the exception
- throw new UnexpectedStateException($this, self::EXCEPTION_INVALID_STATE);
- } // END - if
- }
-
- /**
- * Checks whether the peer's state is 'connected'
- *
- * @return $isConnected Whether the state is 'connected'
- */
- public function isPeerStateConnected () {
- // Just compare it...
- return ($this instanceof ConnectedPeerState);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Connected peer state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ConnectedPeerState extends BasePeerState implements PeerStateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName(BaseRawDataHandler::SOCKET_CONNECTED);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a PeerStateable class
- */
- public final static function createConnectedPeerState () {
- // Get new instance
- $stateInstance = new ConnectedPeerState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ConnectionRefused peer state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ConnectionRefusedPeerState extends BasePeerState implements PeerStateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a PeerStateable class
- */
- public final static function createConnectionRefusedPeerState () {
- // Get new instance
- $stateInstance = new ConnectionRefusedPeerState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ConnectionTimedOut peer state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ConnectionTimedOutPeerState extends BasePeerState implements PeerStateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_CONNECTION_TIMED_OUT);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a PeerStateable class
- */
- public final static function createConnectionTimedOutPeerState () {
- // Get new instance
- $stateInstance = new ConnectionTimedOutPeerState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A NoRouteToHost peer state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NoRouteToHostPeerState extends BasePeerState implements PeerStateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_NO_ROUTE_TO_HOST);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a PeerStateable class
- */
- public final static function createNoRouteToHostPeerState () {
- // Get new instance
- $stateInstance = new NoRouteToHostPeerState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A OperationAlreadyProgress peer state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 OperationAlreadyProgressPeerState extends BasePeerState implements PeerStateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a PeerStateable class
- */
- public final static function createOperationAlreadyProgressPeerState () {
- // Get new instance
- $stateInstance = new OperationAlreadyProgressPeerState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A Problem peer state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ProblemPeerState extends BasePeerState implements PeerStateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_UNKNOWN);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a PeerStateable class
- */
- public final static function createProblemPeerState () {
- // Get new instance
- $stateInstance = new ProblemPeerState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A TransportEndpointGone peer state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 TransportEndpointGonePeerState extends BasePeerState implements PeerStateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a PeerStateable class
- */
- public final static function createTransportEndpointGonePeerState () {
- // Get new instance
- $stateInstance = new TransportEndpointGonePeerState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Init peer state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 InitPeerState extends BasePeerState implements PeerStateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('init');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $stateInstance An instance of a PeerStateable class
- */
- public final static function createInitPeerState () {
- // Get new instance
- $stateInstance = new InitPeerState();
-
- // Return the prepared instance
- return $stateInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A helper class for maintaining connection statistics, no instance is
- * required to use this class.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
- *
- * 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 ConnectionStatisticsHelper extends BaseHubSystem {
- /**
- * Statistics array
- * @TODO Add more protocols to use
- */
- private static $connectionStatistics = array(
- // Statistics for TCP connections
- 'tcp' => array(
- // Tried TCP connection attempts
- 'retry_count' => array(),
- ),
- // Statistics for UDP connections
- 'udp' => array(
- // Tried UDP connection attempts
- 'retry_count' => array(),
- )
- );
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- parent::__construct(__CLASS__);
- }
-
- /**
- * Checks whether the retry count has reached a configured limit for given
- * connection.
- *
- * @param $helperInstance An instance of a ConnectionHelper class
- * @return $isExhausted Whether the retry count has been reached
- */
- public static function isConnectRetryExhausted (ConnectionHelper $helperInstance) {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - CALLED!');
- // Construct config entry
- $configEntry = $helperInstance->getProtocolName() . '_connect_retry_max';
-
- // Check it out
- $isExhausted = (
- (
- isset(self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'])
- ) && (
- self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'] >= $helperInstance->getConfigInstance()->getConfigEntry($configEntry)
- )
- );
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!');
- return $isExhausted;
- }
-
- /**
- * Increaes connect-retry count for given connection
- *
- * @param $helperInstance An instance of a ConnectionHelper class
- * @return void
- */
- public static function increaseConnectRetry (ConnectionHelper $helperInstance) {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - CALLED!');
- // Is the counter there
- if (!isset(self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'])) {
- // First attempt
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - FIRST!');
- self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count'] = 1;
- } else {
- // Next attempt
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-STATISTICS[' . __METHOD__ . ':' . __LINE__ . ']: helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!');
- self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['retry_count']++;
- }
-
- // Create/update 'last_update' for purging
- // @TODO last_update is not being used at the moment
- self::$connectionStatistics[$helperInstance->getProtocolName()][$helperInstance->__toString()]['last_update'] = time();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A class for handling incoming (encoded) raw data with start and end markers.
- * The "stream" is being verified by its length (if modulo 4 of it is always
- * zero) and if the "stream" contains all valid characters (the BASE64
- * "alphabet").
- *
- * Since the latest refacturing this class works "handler-less".
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 RawDataInputStream extends BaseStream implements InputStream {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this node class
- *
- * @return $streamInstance An instance of this node class
- */
- public final static function createRawDataInputStream () {
- // Get a new instance
- $streamInstance = new RawDataInputStream();
-
- // Return the instance
- return $streamInstance;
- }
-
- /**
- * Streams the data and maybe does something to it
- *
- * @param $data The data (string mostly) to "stream"
- * @return $data The data (string mostly) to "stream"
- * @todo Do we need to do something more here?
- * @throws Base64EncodingModuloException If the data's length modulo 4 is not zero
- * @throws Base64EncodingBadException If the data contains characters which are not in the "alphabet" of BASE64 messages.
- * @throws MultipleMessageSentException If the sender has sent two messages and both end up here
- */
- public function streamData ($data) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RAW-INPUT-STREAM[' . __METHOD__ . ':' . __LINE__ . ': data(' . strlen($data) . ')=' . $data);
-
- // Do we have start and end marker again?
- assert($this->ifStartEndMarkersSet($data));
-
- // Count of start and end markers must be the same
- assert(substr_count($data, BaseRawDataHandler::STREAM_START_MARKER) == substr_count($data, BaseRawDataHandler::STREAM_END_MARKER));
-
- // Check if more than two start markers exist and if so, split it.
- if (substr_count($data, BaseRawDataHandler::STREAM_START_MARKER) > 1) {
- // Please do it outside this method
- throw new MultipleMessageSentException(array($this, $data), BaseHubSystem::EXCEPTION_MULTIPLE_MESSAGE_SENT);
- } // END - if
-
- // Remove both
- $data = substr($data, strlen(BaseRawDataHandler::STREAM_START_MARKER), -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER));
-
- // Can it be validated?
- if ((strlen($data) % 4) != 0) {
- // Length modulo 4 must be zero, else it is an invalid Base64 message
- throw new Base64EncodingModuloException(array($this, $data), BaseHubSystem::EXCEPTION_BASE64_ENCODING_NOT_MODULO_4);
- } elseif (!$this->isBase64Encoded($data)) {
- // Is not a valid Base64-encoded message
- throw new Base64EncodingBadException(array($this, $data), BaseHubSystem::EXCEPTION_BASE64_BAD_ENCODING);
- } else {
- // Decode the data with BASE64-encoding
- $data = base64_decode($data);
- }
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RAW-INPUT-STREAM: Length of data is now ' . strlen($data) . ' Bytes.');
-
- // Return it
- return $data;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A RawDataOutputStream class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 RawDataOutputStream extends BaseStream implements OutputStream {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this node class
- *
- * @return $streamInstance An instance of this node class
- */
- public final static function createRawDataOutputStream () {
- // Get a new instance
- $streamInstance = new RawDataOutputStream();
-
- // Return the instance
- return $streamInstance;
- }
-
- /**
- * Streams the data and maybe does something to it
- *
- * @param $data The data (string mostly) to "stream"
- * @return $data The data (string mostly) to "stream"
- */
- public function streamData ($data) {
- /*
- * Encode the data with BASE64 encoding and put it in a "frame":
- *
- * [[S]] - Start marker
- * [[E]] - End marker
- */
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RAW-OUTPUT-STREAM[' . __METHOD__ . ':' . __LINE__ . ']: data()=' . strlen($data) . ' - BEFORE!');
- $data = BaseRawDataHandler::STREAM_START_MARKER . base64_encode($data) . BaseRawDataHandler::STREAM_END_MARKER;
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RAW-OUTPUT-STREAM[' . __METHOD__ . ':' . __LINE__ . ']: data(' . strlen($data) . ')=' . $data);
-
- // Return it
- return $data;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? tags class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Tags extends BaseTags implements Tagable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $tagsInstance An instance of a Tagable class
- */
- public final static function create???Tags () {
- // Get new instance
- $tagsInstance = new ???Tags();
-
- // Return the prepared instance
- return $tagsInstance;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general Tags class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 BaseTags extends BaseHubSystem implements Registerable {
- /**
- * An array with all tags
- */
- private $tags = array();
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Setter for whole tags array
- *
- * @param $tags A new simple array with tags
- * @return void
- */
- protected final function setTags (array $tags) {
- $this->tags = $tags;
- }
-
- /**
- * Getter for whole tags array
- *
- * @return $tags A new simple array with tags
- */
- protected final function getTags () {
- return $this->tags;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Package tags class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 PackageTags extends BaseTags implements Tagable {
- // Exception codes
- const EXCEPTION_INVALID_TAG = 0x160;
-
- /**
- * Last found protocol instance
- */
- private $lastProtocol = NULL;
-
- /**
- * Last found recipient type
- */
- private $lastRecipientType = 'invalid';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init the object registry
- $this->initObjectRegistry();
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $tagsInstance An instance of a Tagable class
- */
- public static final function createPackageTags () {
- // Get new instance
- $tagsInstance = new PackageTags();
-
- // Return the prepared instance
- return $tagsInstance;
- }
-
- /**
- * Loads the XML file (our "object registry") and saves an instance for
- * faster re-use.
- *
- * @return void
- */
- private function initObjectRegistry () {
- // Output debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Initializing object registry - CALLED!');
-
- // Get the application instance
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Get a XML template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_object_registry_template_class');
-
- // Set it for later use
- $this->setTemplateInstance($templateInstance);
-
- // Read the XML file
- $this->getTemplateInstance()->loadXmlTemplate();
-
- // Render the XML content
- $this->getTemplateInstance()->renderXmlContent();
-
- // Output debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Initializing object registry - EXIT!');
- }
-
- /**
- * Extracts the tags from given package data
- *
- * @param $packageData Raw package data
- * @return void
- */
- private function extractTagsFromPackageData (array $packageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE));
-
- /*
- * We take a look at the tags (in most cases only one is needed) so
- * first we need the content data splitted up into all it's parts.
- */
- $contentData = explode(NetworkPackage::PACKAGE_MASK_SEPARATOR, $packageData[NetworkPackage::PACKAGE_DATA_CONTENT]);
-
- // Get the tags and store them locally
- $this->setTags(explode(NetworkPackage::PACKAGE_TAGS_SEPARATOR, $contentData[NetworkPackage::INDEX_TAGS]));
- }
-
- /**
- * Verifies all tags by looking them up in an XML file. This method is
- * the key method to make sure only known objects are being distributed and
- * shared over the whole hub-network. So if the "tag" (let's better say
- * object type) isn't found in that XML the package won't be distributed.
- *
- * @param $packageData Raw package data
- * @return void
- * @throws InvalidTagException If a provided tag from the package data is invalid
- */
- private function verifyAllTags (array $packageData) {
- // Get the registry
- $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
-
- // "Walk" over all tags
- foreach ($this->getTags() as $tag) {
- // Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Validating tag ' . $tag . ' ...');
-
- // Get an array from this tag
- $entry = $objectRegistryInstance->getArrayFromKey(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME, $tag);
-
- /*
- * If it is no array or the array is empty or an entry is missing
- * the entry is invalid.
- */
- if ((!is_array($entry)) || (count($entry) == 0) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL])) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]))) {
- // Invalid entry found
- throw new InvalidTagException(array($this, $tag), self::EXCEPTION_INVALID_TAG);
- } // END - if
-
- // Now save the last discovered protocol/recipient type
- $this->lastProtocol = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
- $this->lastRecipientType = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE];
- } // END - foreach
- }
-
- /**
- * Chooses the right protocol from given package data
- *
- * @param $packageData Raw package data
- * @return $lastProtocol An instance of the last used HandleableProtocol class
- */
- public function chooseProtocolFromPackageData (array $packageData) {
- // Extract the tags
- $this->extractTagsFromPackageData($packageData);
-
- // Now we need to verify every single tag
- $this->verifyAllTags($packageData);
-
- // Return the last (and only) found protocol (e.g. 'tcp' is very usual)
- return $this->lastProtocol;
- }
-
- /**
- * Checks whether the given package data is accepted by the listener
- *
- * @param $packageData Raw package data
- * @param $listenerInstance A Listenable instance
- * @return $accepts Whether it is accepted
- */
- public function ifPackageDataIsAcceptedByListener (array $packageData, Listenable $listenerInstance) {
- // Extract the tags
- $this->extractTagsFromPackageData($packageData);
-
- // Now we need to verify every single tag
- $this->verifyAllTags($packageData);
-
- // Now simply check it out
- $accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid'));
-
- // And return the result
- return $accepts;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? task for apt-proxy consoles
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Apt-Proxy Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 AptProxy???Task extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createAptProxy???Task () {
- // Get new instance
- $taskInstance = new AptProxy???Task();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A proxy listener task for apt-proxy consoles
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Chat 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 AptProxyListenerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createAptProxyListenerTask () {
- // Get new instance
- $taskInstance = new AptProxyListenerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? task for chat consoles
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Chat???Task extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createChat???Task () {
- // Get new instance
- $taskInstance = new Chat???Task();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A TelnetListener task for chat consoles
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2012 Chat 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 ChatTelnetListenerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createChatTelnetListenerTask () {
- // Get new instance
- $taskInstance = new ChatTelnetListenerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A general URL source Task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 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 BaseUrlSourceTask extends BaseTask {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Initializes URL source task (to keep the constructor small)
- *
- * @return void
- */
- protected function initUrlSourceTask () {
- // Get source instance
- $sourceInstance = UrlSourceObjectFactory::createUrlSourceInstance($this);
-
- // And set it here
- $this->setUrlSourceInstance($sourceInstance);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Crawler???Task extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawler???Task () {
- // Get new instance
- $taskInstance = new Crawler???Task();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A NodeCommunicator task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerNodeCommunicatorTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerNodeCommunicatorTask () {
- // Get new instance
- $taskInstance = new CrawlerNodeCommunicatorTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get the communicator instance
- $communicatorInstance = CommunicatorFactory::createCommunicatorInstance('crawler_node_communicator_class', 'node');
-
- // Get the current crawler state from registry
- $stateInstance = Registry::getRegistry()->getInstance('crawler')->getStateInstance();
-
- // Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
-
- // We can now invoke that state instance and pass our communicator instance for generating some test units
- $stateInstance->executeState($communicatorInstance);
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A DocumentParser task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerDocumentParserTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerDocumentParserTask () {
- // Get new instance
- $taskInstance = new CrawlerDocumentParserTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A MimeSniffer task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerMimeSnifferTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerMimeSnifferTask () {
- // Get new instance
- $taskInstance = new CrawlerMimeSnifferTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Ping task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerPingTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerPingTask () {
- // Get new instance
- $taskInstance = new CrawlerPingTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A RemoteJobPublisher task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerRemoteJobPublisherTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerRemoteJobPublisherTask () {
- // Get new instance
- $taskInstance = new CrawlerRemoteJobPublisherTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? scanner task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Crawler???ScannerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawler???ScannerTask () {
- // Get new instance
- $taskInstance = new Crawler???ScannerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Call factory for a scanner instance and execute it
- ScannerFactory::createScannerInstance($this)->execute();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A UploadedList scanner task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerUploadedListScannerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerUploadedListScannerTask () {
- // Get new instance
- $taskInstance = new CrawlerUploadedListScannerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Call factory for a scanner instance and execute it
- ScannerObjectFactory::createScannerInstance($this)->execute();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A SnippetExtractor task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerSnippetExtractorTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerSnippetExtractorTask () {
- // Get new instance
- $taskInstance = new CrawlerSnippetExtractorTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A StructureAnalyzer task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerStructureAnalyzerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerStructureAnalyzerTask () {
- // Get new instance
- $taskInstance = new CrawlerStructureAnalyzerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A LocalUrlCrawler task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerLocalUrlCrawlerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerLocalUrlCrawlerTask () {
- // Get new instance
- $taskInstance = new CrawlerLocalUrlCrawlerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A RemoteUrlCrawler task for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerRemoteUrlCrawlerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerRemoteUrlCrawlerTask () {
- // Get new instance
- $taskInstance = new CrawlerRemoteUrlCrawlerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An URL source task for ??? for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerUrlSource???Task extends BaseUrlSourceTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawler???Task () {
- // Get new instance
- $taskInstance = new Crawler???Task();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get source instance
- $sourceInstance = $this->getUrlSourceInstance();
-
- // Is it not set?
- if (is_null($sourceInstance)) {
- // Initialize it
- $this->initUrlSourceTask();
-
- // And re-get it
- $sourceInstance = $this->getUrlSourceInstance();
- } // END - if
-
- // Get the URL source instance and fill the stack with crawl entries
- $sourceInstance->fillUrlStack();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * An URL source task for FoundRss for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerUrlSourceFoundRssTask extends BaseUrlSourceTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerUrlSourceFoundRssTask () {
- // Get new instance
- $taskInstance = new CrawlerUrlSourceFoundRssTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get source instance
- $sourceInstance = $this->getUrlSourceInstance();
-
- // Is it not set?
- if (is_null($sourceInstance)) {
- // Initialize it
- $this->initUrlSourceTask();
-
- // And re-get it
- $sourceInstance = $this->getUrlSourceInstance();
- } // END - if
-
- // Get the URL source instance and fill the stack with crawl entries
- $sourceInstance->fillUrlStack();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * An URL source task for LocalStart for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerUrlSourceLocalStartTask extends BaseUrlSourceTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerUrlSourceLocalStartTask () {
- // Get new instance
- $taskInstance = new CrawlerUrlSourceLocalStartTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get source instance
- $sourceInstance = $this->getUrlSourceInstance();
-
- // Is it not set?
- if (is_null($sourceInstance)) {
- // Initialize it
- $this->initUrlSourceTask();
-
- // And re-get it
- $sourceInstance = $this->getUrlSourceInstance();
- } // END - if
-
- // Get the URL source instance and fill the stack with crawl entries
- $sourceInstance->fillUrlStack();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * An URL source task for RssStart for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerUrlSourceRssStartTask extends BaseUrlSourceTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerUrlSourceRssStartTask () {
- // Get new instance
- $taskInstance = new CrawlerUrlSourceRssStartTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get source instance
- $sourceInstance = $this->getUrlSourceInstance();
-
- // Is it not set?
- if (is_null($sourceInstance)) {
- // Initialize it
- $this->initUrlSourceTask();
-
- // And re-get it
- $sourceInstance = $this->getUrlSourceInstance();
- } // END - if
-
- // Get the URL source instance and fill the stack with crawl entries
- $sourceInstance->fillUrlStack();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * An URL source task for UploadedList for crawlers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Crawler Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 CrawlerUrlSourceUploadedListTask extends BaseUrlSourceTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCrawlerUrlSourceUploadedListTask () {
- // Get new instance
- $taskInstance = new CrawlerUrlSourceUploadedListTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get source instance
- $sourceInstance = $this->getUrlSourceInstance();
-
- // Is it not set?
- if (is_null($sourceInstance)) {
- // Initialize it
- $this->initUrlSourceTask();
-
- // And re-get it
- $sourceInstance = $this->getUrlSourceInstance();
- } // END - if
-
- // Get the URL source instance and fill the stack with crawl entries
- $sourceInstance->fillUrlStack();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? task for crunchers
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2012 Cruncher Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Cruncher???Task extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createCruncher???Task () {
- // Get new instance
- $taskInstance = new Cruncher???Task();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A KeyProducer task for crunchers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherKeyProducerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public final static function createCruncherKeyProducerTask () {
- // Get new instance
- $taskInstance = new CruncherKeyProducerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get the instance
- $producerInstance = ProducerFactory::createProducerInstance('cruncher_key_producer_class', 'key');
-
- // Get the current cruncher state from registry
- $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance();
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
-
- // We can now invoke that state instance and pass our producer instance for generating some test units
- $stateInstance->executeState($producerInstance);
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A TestUnitProducer task for crunchers
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherTestUnitProducerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public final static function createCruncherTestUnitProducerTask () {
- // Get new instance
- $taskInstance = new CruncherTestUnitProducerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get the producer instance
- $producerInstance = ProducerFactory::createProducerInstance('cruncher_test_unit_producer_class', 'test_unit');
-
- // Get the current cruncher state from registry
- $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance();
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
-
- // We can now invoke that state instance and pass our producer instance for generating some test units
- $stateInstance->executeState($producerInstance);
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A WorkUnitFetcher task for crunchers which asks the cruncher to fetch work
- * units or, if enabled in configuration, work on some test units.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher 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 CruncherWorkUnitFetcherTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public final static function createCruncherWorkUnitFetcherTask () {
- // Get new instance
- $taskInstance = new CruncherWorkUnitFetcherTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- /*
- * Get the cruncher instance and call a method which should check if
- * the in-buffer is going to depleted. If so, new WUs are fetched from
- * network or (if enabled in config) a random test WU is being
- * generated. This test WU is for developing only or, if you like, to
- * test your cruncher loop.
- *
- * Please report any bugs you encounter to me.
- */
- Registry::getRegistry()->getInstance('cruncher')->doFetchWorkUnits();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A BlockFetcher task for miners which asks the network for new blocks and
- * starts the "block chain" fetching if no block has been fetched so far.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Miner 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 MinerBlockFetcherTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public final static function createMinerBlockFetcherTask () {
- // Get new instance
- $taskInstance = new MinerBlockFetcherTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- /*
- * Get the miner instance and call a method which should check if
- * the in-buffer is going to depleted. If so, new WUs are fetched from
- * network or (if enabled in config) a random test WU is being
- * generated. This test WU is for developing only or, if you like, to
- * test your miner loop.
- *
- * Please report any bugs you encounter to me.
- */
- Registry::getRegistry()->getInstance('miner')->doSearchForBlocks();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A RealGenesisBlockProducer task for miners
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerRealGenesisBlockProducerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public final static function createMinerRealGenesisBlockProducerTask () {
- // Get new instance
- $taskInstance = new MinerRealGenesisBlockProducerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get the producer instance
- $producerInstance = ProducerFactory::createProducerInstance('miner_real_genesis_block_producer_class', 'real_unit');
-
- // Get the current miner state from registry
- $stateInstance = Registry::getRegistry()->getInstance('miner')->getStateInstance();
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
-
- // We can now invoke that state instance and pass our producer instance for generating some test units
- $stateInstance->executeState($producerInstance);
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A TestGenesisBlockProducer task for miners
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner 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 MinerTestGenesisBlockProducerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public final static function createMinerTestGenesisBlockProducerTask () {
- // Get new instance
- $taskInstance = new MinerTestGenesisBlockProducerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get the producer instance
- $producerInstance = ProducerFactory::createProducerInstance('miner_test_genesis_block_producer_class', 'test_unit');
-
- // Get the current miner state from registry
- $stateInstance = Registry::getRegistry()->getInstance('miner')->getStateInstance();
-
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
-
- // We can now invoke that state instance and pass our producer instance for generating some test units
- $stateInstance->executeState($producerInstance);
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? task for miners
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Miner???Task extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createMiner???Task () {
- // Get new instance
- $taskInstance = new Miner???Task();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A MinerCommunicator task for miners
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2014 Miner Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 MinerNodeCommunicatorTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createMinerNodeCommunicatorTask () {
- // Get new instance
- $taskInstance = new MinerNodeCommunicatorTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get the communicator instance
- $communicatorInstance = CommunicatorFactory::createCommunicatorInstance('miner_node_communicator_class', 'node');
-
- // Get the current miner state from it
- $stateInstance = $communicatorInstance->getStateInstance();
-
- // Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
-
- // We can now invoke that state instance and pass our communicator instance for generating some test units
- $stateInstance->executeState($communicatorInstance);
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? task for NetworkPackage
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 NetworkPackage???Task extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNetworkPackage???Task () {
- // Get new instance
- $taskInstance = new NetworkPackage???Task();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0%
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A NetworkPackageReader task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NetworkPackageReaderTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public static final function createNetworkPackageReaderTask () {
- // Get new instance
- $taskInstance = new NetworkPackageReaderTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Also visit some sub-objects?
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // "Cache" package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Do we have something to handle?
- if ($packageInstance->isProcessedMessagePending()) {
- /*
- * A previously proccessed message is waiting for being
- * "interpreted". This is done by trying to find a configuration
- * entry based on 'message_type' element.
- */
- $packageInstance->handleProcessedMessage();
- } elseif ($packageInstance->isNewMessageArrived()) {
- /*
- * A fully "decoded" message has been received and added for being
- * processed. Processing a message should not take long, so mostly
- * this step involves reading all data through a XML template engine
- * as "XML variables" from the content (which must be a well-formed
- * XML) and then pushing it on the next stack "processed messages".
- */
- $packageInstance->handleNewlyArrivedMessage();
- } elseif ($packageInstance->isIncomingRawDataHandled()) {
- /*
- * Incoming decoded data has been handled (see below) so it needs to
- * be assembled back to a "package array". Please see NetworkPackage
- * for further details (what array elements are required et cetera).
- */
- $packageInstance->assembleDecodedDataToPackage();
- } elseif ($packageInstance->ifMultipleMessagesPending()) {
- /*
- * Some raw data contained multiple messages which where now splitted.
- */
- $packageInstance->handleMultipleMessages();
- } elseif ($packageInstance->isNewRawDataPending()) {
- // Raw, decoded data has been received
- $packageInstance->handleIncomingDecodedData();
- } elseif ($packageInstance->ifAssemblerHasPendingDataLeft()) {
- // Handle any pending data from the package assembler
- $packageInstance->handleAssemblerPendingData();
- } // END - if
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A NetworkPackageWriter task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NetworkPackageWriterTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public static final function createNetworkPackageWriterTask () {
- // Get new instance
- $taskInstance = new NetworkPackageWriterTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Also visit some sub-objects?
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // "Cache" package instance
- $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
-
- // Do we have something to deliver?
- if ($packageInstance->isEncodedDataPending()) {
- // Sent encoded (raw) data
- $packageInstance->sendEncodedData();
- } elseif ($packageInstance->isPackageWaitingForDelivery()) {
- // Sent it finally out
- $packageInstance->sendWaitingPackage();
- } elseif ($packageInstance->isPackageDeclared()) {
- // Prepare package for delivery
- $packageInstance->processDeclaredPackage();
- } elseif ($packageInstance->isPackageEnqueued()) {
- // Okay, then deliver (better discover its recipients) this package
- $packageInstance->declareEnqueuedPackage();
- }
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Announcement node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeAnnouncementTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public static final function createNodeAnnouncementTask () {
- // Get new instance
- $taskInstance = new NodeAnnouncementTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get the node instance and announce us
- NodeObjectFactory::createNodeInstance()->announceToUpperNodes($this);
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ChunkAssembler node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeChunkAssemblerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodeChunkAssemblerTask () {
- // Get new instance
- $taskInstance = new NodeChunkAssemblerTask();
-
- // Get a chunk handler instance
- $handlerInstance = ChunkHandlerFactory::createChunkHandlerInstance();
-
- // And add it to this task instance
- $taskInstance->setHandlerInstance($handlerInstance);
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Also visit some sub-objects?
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // "Cache" handler instance
- $handlerInstance = $this->getHandlerInstance();
-
- // Are there chunks to handle or a final array to assemble?
- if ($handlerInstance->ifUnassembledChunksAvailable()) {
- /*
- * Then do the final steps:
- *
- * 1) Sort the final array with ksort(). This will bring the "hash
- * chunk" up to the last array index and the EOP chunk to the
- * pre-last array index
- * 2) Assemble all chunks except two last (see above step)
- * 3) While so, do the final check on all hashes
- * 4) If the package is assembled back together, hash it again for
- * the very final verification.
- */
- $handlerInstance->assembleChunksFromFinalArray();
- } elseif ($handlerInstance->ifUnhandledChunksWithFinalAvailable()) {
- /*
- * Then handle them (not all!). This should push all chunks into a
- * 'final array' for last verification.
- */
- $handlerInstance->handleAvailableChunksWithFinal();
- } elseif ($handlerInstance->ifRawPackageDataIsAvailable()) {
- /*
- * The final raw package data is back together again. So feed it
- * into the next stack for further decoding/processing
- */
- $handlerInstance->handledAssembledRawPackageData();
- }
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? node-task
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Node???Task extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNode???Task () {
- // Get new instance
- $taskInstance = new Node???Task();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0% done
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A PackageDecoder node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodePackageDecoderTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodePackageDecoderTask () {
- // Get new instance
- $taskInstance = new NodePackageDecoderTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get a decoder instance
- $decoderInstance = DecoderFactory::createPackageDecoderInstance();
-
- // Check if the stacker has some entries left
- if ($decoderInstance->ifUnhandledRawPackageDataLeft()) {
- // Then handle it
- $decoderInstance->handleRawPackageData();
- } elseif ($decoderInstance->ifDeocedPackagesLeft()) {
- // Some decoded packages have arrived (for this peer)
- $decoderInstance->handleDecodedPackage();
- }
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? node DHT task
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 NodeDht???Task extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodeDht???Task () {
- // Get new instance
- $taskInstance = new NodeDht???Task();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0% done
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A DhtBootstrap node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtBootstrapTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodeDhtBootstrapTask () {
- // Get new instance
- $taskInstance = new NodeDhtBootstrapTask();
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set the DHT instance here
- $taskInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Let the DHT class do the work for us
- $this->getDhtInstance()->bootstrapDht();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A DhtInitialization node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtInitializationTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodeDhtInitializationTask () {
- // Get new instance
- $taskInstance = new NodeDhtInitializationTask();
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set the DHT instance here
- $taskInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Intiailize the DHT
- $this->getDhtInstance()->initDht();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A DhtBootstrap node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtLateBootstrapTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodeDhtLateBootstrapTask () {
- // Get new instance
- $taskInstance = new NodeDhtLateBootstrapTask();
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set the DHT instance here
- $taskInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Let the DHT class do the work for us
- $this->getDhtInstance()->bootstrapDht();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A DhtPublicationCheck node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtPublicationCheckTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodeDhtPublicationCheckTask () {
- // Get new instance
- $taskInstance = new NodeDhtPublicationCheckTask();
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set the DHT instance here
- $taskInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo Add more?
- */
- public function executeTask () {
- // Get DHT instance
- $dhtInstance = $this->getDhtInstance();
-
- // Has the DHT some unpublished entries?
- if (($dhtInstance->hasFullyBootstrapped()) && ($dhtInstance->hasUnpublishedEntries())) {
- // Then initiate publishing them
- $dhtInstance->initEntryPublication();
- } // END - if
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A DhtPublication node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtPublicationTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodeDhtPublicationTask () {
- // Get new instance
- $taskInstance = new NodeDhtPublicationTask();
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set the DHT instance here
- $taskInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo Add more?
- */
- public function executeTask () {
- // Get DHT instance
- $dhtInstance = $this->getDhtInstance();
-
- // Has the DHT some entries pending publication?
- if ($dhtInstance->hasEntriesPendingPublication()) {
- // Then publish next entry
- $dhtInstance->publishEntry();
- } // END - if
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A DhtQuery node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeDhtQueryTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodeDhtQueryTask () {
- // Get new instance
- $taskInstance = new NodeDhtQueryTask();
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set the DHT instance here
- $taskInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo ~5% done
- */
- public function executeTask () {
- // Get DHT instance
- $dhtInstance = $this->getDhtInstance();
-
- // Are there "INSERT" node data entries?
- if ($dhtInstance->ifInsertNodeDataPending()) {
- // Then insert a single entry
- $dhtInstance->insertSingleNodeData();
- } // END - if
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A HubSocketListener task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeSocketListenerTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public static final function createNodeSocketListenerTask () {
- // Get new instance
- $taskInstance = new NodeSocketListenerTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Get the node instance from registry
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Visit the pool listener task
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('LISTENER-TASK[' . __METHOD__ . ':' . __LINE__ . ']: Going to visit object ' . $nodeInstance->getListenerPoolInstance()->__toString() . ' ...');
- $nodeInstance->getListenerPoolInstance()->accept($visitorInstance);
-
- // Visit this task
- // @TODO Do we need to visit this task? $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0% done
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Ping node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodePingTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $listInstance A Listable instance
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public static final function createNodePingTask (Listable $listInstance) {
- // Get new instance
- $taskInstance = new NodePingTask();
-
- // Se the list instance in this task
- $taskInstance->setListInstance($listInstance);
-
- // Init ping iterator instance
- $iteratorInstance = $listInstance->getListIterator();
-
- // Set it as well
- $taskInstance->setIteratorInstance($iteratorInstance);
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Also visit some sub-objects?
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- * @todo 0% done
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A SelfConnect node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeSelfConnectTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public static final function createNodeSelfConnectTask () {
- // Get new instance
- $taskInstance = new NodeSelfConnectTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get the node instance and try it
- NodeObjectFactory::createNodeInstance()->doSelfConnection($this);
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A PackageTagsInit node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodePackageTagsInitTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Visitable class
- */
- public final static function createNodePackageTagsInitTask () {
- // Get new instance
- $taskInstance = new NodePackageTagsInitTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo Maybe visit some sub-objects
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- // Get a factory instance and do no more as this loads the object (tags) registry
- $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A UpdateCheck node-task
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeUpdateCheckTask extends BaseTask implements Taskable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $taskInstance An instance of a Taskable/Visitable class
- */
- public static final function createNodeUpdateCheckTask () {
- // Get new instance
- $taskInstance = new NodeUpdateCheckTask();
-
- // Return the prepared instance
- return $taskInstance;
- }
-
- /**
- * Accepts the visitor to process the visitor
- *
- * @param $visitorInstance An instance of a Visitor class
- * @return void
- * @todo 0%
- */
- public function accept (Visitor $visitorInstance) {
- // Visit this task
- $visitorInstance->visitTask($this);
- }
-
- /**
- * Executes the task
- *
- * @return void
- */
- public function executeTask () {
- $this->partialStub('Unimplemented task.');
- }
-
- /**
- * Shuts down the task
- *
- * @return void
- * @todo 0% done
- */
- public function doShutdown () {
- self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Shutting down...');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An Announcement template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Some XML nodes must be available for later data extraction
- */
- const ANNOUNCEMENT_DATA_SESSION_ID = 'session-id';
- const ANNOUNCEMENT_DATA_NODE_ID = 'node-id';
- const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'private-key-hash';
- const ANNOUNCEMENT_DATA_NODE_STATUS = 'node-status';
- const ANNOUNCEMENT_DATA_NODE_MODE = 'node-mode';
- const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'external-address';
- const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'internal-address';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->setSubNodes(array(
- 'announcement-data',
- 'listener',
- self::ANNOUNCEMENT_DATA_NODE_STATUS,
- self::ANNOUNCEMENT_DATA_NODE_MODE,
- self::ANNOUNCEMENT_DATA_NODE_ID,
- self::ANNOUNCEMENT_DATA_SESSION_ID,
- self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
- self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
- 'object-type-list',
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlAnnouncementTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlAnnouncementTemplateEngine();
-
- // Init template instance
- $templateInstance->initXmlTemplateEngine('node', 'announcement');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- /*
- * Assign the found characters to variable and use the last entry from
- * stack as the name.
- */
- parent::assignVariable($this->getStackInstance()->getNamed('node_announcement'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getMenuCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the announcement
- *
- * @return void
- */
- protected function startAnnouncement () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', 'announcement');
- }
-
- /**
- * Starts the announcement data
- *
- * @return void
- */
- protected function startAnnouncementData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', 'announcement-data');
- }
-
- /**
- * Starts the node status
- *
- * @return void
- */
- protected function startNodeStatus () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
- }
-
- /**
- * Starts the node-mode
- *
- * @return void
- */
- protected function startNodeMode () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_MODE);
- }
-
- /**
- * Starts the listener
- *
- * @return void
- */
- protected function startListener () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', 'listener');
- }
-
- /**
- * Starts the session id
- *
- * @return void
- */
- protected function startSessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
- }
-
- /**
- * Starts the node id
- *
- * @return void
- */
- protected function startNodeId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_ID);
- }
-
- /**
- * Starts the private key hash
- *
- * @return void
- */
- protected function startPrivateKeyHash () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
- }
-
- /**
- * Starts the public ip
- *
- * @return void
- */
- protected function startExternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
- }
-
- /**
- * Starts the private ip
- *
- * @return void
- */
- protected function startInternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
- }
-
- /**
- * Starts the object type list
- *
- * @return void
- */
- protected function startObjectTypeList () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', 'object-type-list');
- }
-
- /**
- * Starts the object type
- *
- * @return void
- */
- protected function startObjectType () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', 'object-type');
- }
-
- /**
- * Finishes the object type
- *
- * @return void
- */
- protected function finishObjectType () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the object type list
- *
- * @return void
- */
- protected function finishObjectTypeList () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the private key hash
- *
- * @return void
- */
- protected function finishPrivateKeyHash () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the node id
- *
- * @return void
- */
- protected function finishNodeId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the session id
- *
- * @return void
- */
- protected function finishSessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the private ip
- *
- * @return void
- */
- protected function finishInternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the public ip
- *
- * @return void
- */
- protected function finishExternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the listener
- *
- * @return void
- */
- protected function finishListener () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the node mode
- *
- * @return void
- */
- protected function finishNodeMode () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the node status
- *
- * @return void
- */
- protected function finishNodeStatus () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the announcement data
- *
- * @return void
- */
- protected function finishAnnouncementData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
- /**
- * Finishes the announcement
- *
- * @return void
- */
- protected function finishAnnouncement () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An AnnouncementAnswer template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Some XML nodes must be available for later data extraction
- */
- const ANNOUNCEMENT_DATA_NODE_ID = 'my-node-id';
- const ANNOUNCEMENT_DATA_SESSION_ID = 'my-session-id';
- const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash';
- const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status';
- const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address';
- const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init sub-nodes array
- $this->setSubNodes(array(
- // These nodes don't contain any data
- 'my-data',
- 'your-data',
- // Data from *this* node
- self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
- self::ANNOUNCEMENT_DATA_NODE_STATUS,
- self::ANNOUNCEMENT_DATA_NODE_ID,
- self::ANNOUNCEMENT_DATA_SESSION_ID,
- self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
- // Data from other node
- 'your-external-address',
- 'your-internal-address',
- 'your-node-id',
- 'your-session-id',
- 'your-private-key-hash',
- // Answer status (generic field)
- self::ANSWER_STATUS,
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlAnnouncementAnswerTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
-
- // Init instance
- $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- * @todo Find something useful with this!
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- /*
- * Assign the found characters to variable and use the last entry from
- * stack as the name.
- */
- parent::assignVariable($this->getStackInstance()->getNamed('node_announcement_answer'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getAnnouncementAnswerCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the announcement-answer
- *
- * @return void
- */
- protected function startAnnouncementAnswer () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
- }
-
- /**
- * Starts the my-data
- *
- * @return void
- */
- protected function startMyData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', 'my-data');
- }
-
- /**
- * Starts the my-external-address
- *
- * @return void
- */
- protected function startMyExternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
- }
-
- /**
- * Starts the my-internal-address
- *
- * @return void
- */
- protected function startMyInternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
- }
-
- /**
- * Starts the my-node-id
- *
- * @return void
- */
- protected function startMyNodeId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_ID);
- }
-
- /**
- * Starts the my-session-id
- *
- * @return void
- */
- protected function startMySessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
- }
-
- /**
- * Starts the my-private-key-hash
- *
- * @return void
- */
- protected function startMyPrivateKeyHash () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
- }
-
- /**
- * Starts the my-status
- *
- * @return void
- */
- protected function startMyStatus () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
- }
-
- /**
- * Finishes the my-status
- *
- * @return void
- */
- protected function finishMyStatus () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the my-private-key-hash
- *
- * @return void
- */
- protected function finishMyPrivateKeyhash () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the my-session-id
- *
- * @return void
- */
- protected function finishMySessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the my-node-id
- *
- * @return void
- */
- protected function finishMyNodeId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the my-internal-address
- *
- * @return void
- */
- protected function finishMyInternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the my-external-address
- *
- * @return void
- */
- protected function finishMyExternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the my-data
- *
- * @return void
- */
- protected function finishMyData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Starts the your-data
- *
- * @return void
- */
- protected function startYourData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-data');
- }
-
- /**
- * Starts the your-external-address
- *
- * @return void
- */
- protected function startYourExternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-external-address');
- }
-
- /**
- * Starts the your-internal-address
- *
- * @return void
- */
- protected function startYourInternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-internal-address');
- }
-
- /**
- * Starts the your-session-id
- *
- * @return void
- */
- protected function startYourSessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-session-id');
- }
-
- /**
- * Starts the your-node-id
- *
- * @return void
- */
- protected function startYourNodeId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-node-id');
- }
-
- /**
- * Starts the your-private-key-hash
- *
- * @return void
- */
- protected function startYourPrivateKeyHash () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-private-key-hash');
- }
-
- /**
- * Finishes the your-private-key-hash
- *
- * @return void
- */
- protected function finishYourPrivateKeyHash () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the your-node-id
- *
- * @return void
- */
- protected function finishYourNodeId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the your-session-id
- *
- * @return void
- */
- protected function finishYourSessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the your-internal-address
- *
- * @return void
- */
- protected function finishYourInternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the your-external-address
- *
- * @return void
- */
- protected function finishYourExternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the your-data
- *
- * @return void
- */
- protected function finishYourData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
- /**
- * Finishes the announcement-answer
- *
- * @return void
- */
- protected function finishAnnouncementAnswer () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * An ??? answer template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 Xml???AnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXml???TemplateEngine () {
- // Get a new instance
- $templateInstance = new Xml???TemplateEngine();
-
- // Init template instannce
- $templateInstance->initXmlTemplateEngine('PREFIX', '!!!');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return false;
- } // END - if
-
- // Assign data with matching variable here
- parent::assignVariable($this->getStackInstance()->getNamed('!!!'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function get???CacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the |||
- *
- * @return void
- */
- protected function start??? () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('!!!', '|||');
- }
-
- /**
- * Finishes the |||
- *
- * @return void
- */
- protected function finish??? () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('!!!');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * An generic answer template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 BaseXmlAnswerTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Generic 'answer-status' field
- */
- const ANSWER_STATUS = 'answer-status';
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Starts the answer-status
- *
- * @return void
- */
- protected function startAnswerStatus () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed($this->getStackerName(), self::ANSWER_STATUS);
- }
-
- /**
- * Finishes the answer-status
- *
- * @return void
- */
- protected function finishAnswerStatus () {
- // Pop the last entry
- $this->getStackInstance()->popNamed($this->getStackerName());
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An DhtBootstrapAnswer template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Some XML nodes must be available for later data extraction
- */
- const DHT_BOOTSTRAP_DATA_SESSION_ID = 'my-session-id';
- const DHT_BOOTSTRAP_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash';
- const DHT_BOOTSTRAP_DATA_NODE_STATUS = 'my-status';
- const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'my-external-address';
- const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'my-internal-address';
- const DHT_BOOTSTRAP_DATA_NODE_LIST = 'dht-nodes-list';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init sub-nodes array
- $this->setSubNodes(array(
- // These nodes don't contain any data
- 'my-data',
- 'your-data',
- // Data from *this* node
- self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
- self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
- self::DHT_BOOTSTRAP_DATA_SESSION_ID,
- // Data from other node
- 'your-external-address',
- 'your-internal-address',
- 'your-session-id',
- // Answer status (generic field)
- self::ANSWER_STATUS,
- // DHT node list
- self::DHT_BOOTSTRAP_DATA_NODE_LIST,
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlDhtBootstrapAnswerTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlDhtBootstrapAnswerTemplateEngine();
-
- // Init instance
- $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap_answer');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- * @todo Find something useful with this!
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- /*
- * Assign the found characters to variable and use the last entry from
- * stack as the name.
- */
- parent::assignVariable($this->getStackInstance()->getNamed('node_dht_bootstrap_answer'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getDhtBootstrapAnswerCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the dht_bootstrap-answer
- *
- * @return void
- */
- protected function startDhtBootstrapAnswer () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'dht_bootstrap-answer');
- }
-
- /**
- * Starts the my-data
- *
- * @return void
- */
- protected function startMyData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'my-data');
- }
-
- /**
- * Starts the my-external-address
- *
- * @return void
- */
- protected function startMyExternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS);
- }
-
- /**
- * Starts the my-internal-address
- *
- * @return void
- */
- protected function startMyInternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS);
- }
-
- /**
- * Starts the my-session-id
- *
- * @return void
- */
- protected function startMySessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
- }
-
- /**
- * Starts the my-private-key-hash
- *
- * @return void
- */
- protected function startMyPrivateKeyHash () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_PRIVATE_KEY_HASH);
- }
-
- /**
- * Starts the my-status
- *
- * @return void
- */
- protected function startMyStatus () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
- }
-
- /**
- * Starts the dht-nodes-list
- *
- * @return void
- */
- protected function startDhtNodesList () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_LIST);
- }
-
- /**
- * Finishes the dht-nodes-list
- *
- * @return void
- */
- protected function finishDhtNodesList () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the my-status
- *
- * @return void
- */
- protected function finishMyStatus () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the my-private-key-hash
- *
- * @return void
- */
- protected function finishMyPrivateKeyHash () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the my-session-id
- *
- * @return void
- */
- protected function finishMySessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the my-internal-address
- *
- * @return void
- */
- protected function finishMyInternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the my-external-address
- *
- * @return void
- */
- protected function finishMyExternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the my-data
- *
- * @return void
- */
- protected function finishMyData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Starts the your-data
- *
- * @return void
- */
- protected function startYourData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-data');
- }
-
- /**
- * Starts the your-external-address
- *
- * @return void
- */
- protected function startYourExternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-external-address');
- }
-
- /**
- * Starts the your-internal-address
- *
- * @return void
- */
- protected function startYourInternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-internal-address');
- }
-
- /**
- * Starts the your-session-id
- *
- * @return void
- */
- protected function startYourSessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-session-id');
- }
-
- /**
- * Starts the your-private-key-hash
- *
- * @return void
- */
- protected function startYourPrivateKeyHash () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-private-key-hash');
- }
-
- /**
- * Finishes the your-private-key-hash
- *
- * @return void
- */
- protected function finishYourPrivateKeyHash () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the your-session-id
- *
- * @return void
- */
- protected function finishYourSessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the your-internal-address
- *
- * @return void
- */
- protected function finishYourInternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the your-external-address
- *
- * @return void
- */
- protected function finishYourExternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the your-data
- *
- * @return void
- */
- protected function finishYourData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
- /**
- * Finishes the dht_bootstrap-answer
- *
- * @return void
- */
- protected function finishDhtBootstrapAnswer () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A RequestNodeListAnswer template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlRequestNodeListAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
- // Constants for array elements
- const REQUEST_DATA_SESSION_ID = 'session-id';
- const REQUEST_DATA_NODE_LIST = 'node-list';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init sub-nodes array
- $this->setSubNodes(array(
- self::REQUEST_DATA_SESSION_ID,
- self::REQUEST_DATA_NODE_LIST,
- // Answer status (generic field)
- self::ANSWER_STATUS,
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlRequestNodeListAnswerTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlRequestNodeListAnswerTemplateEngine();
-
- // Init instance
- $templateInstance->initXmlTemplateEngine('node', 'request_node_list_answer');
-
- // Get a template instance for list entries (as they are dynamic)
- $entriesInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_request_node_list_entries_template_class');
-
- // Set it here
- $templateInstance->setTemplateInstance($entriesInstance);
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- * @todo Find something useful with this!
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- /*
- * Assign the found characters to variable and use the last entry from
- * stack as the name.
- */
- parent::assignVariable($this->getStackInstance()->getNamed('node_request_node_list_answer'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getRequestNodeListAnswerCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the 'request-node-list-answer'
- *
- * @return void
- */
- protected function startRequestNodeListAnswer () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_request_node_list_answer', 'request-node-list-answer');
- }
-
- /**
- * Starts the session-id
- *
- * @return void
- */
- protected function startSessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_request_node_list_answer', self::REQUEST_DATA_SESSION_ID);
- }
-
- /**
- * Starts the node-list
- *
- * @return void
- */
- protected function startNodeList () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_request_node_list_answer', self::REQUEST_DATA_NODE_LIST);
- }
-
- /**
- * Finishes the node-list
- *
- * @return void
- */
- protected function finishNodeList () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_request_node_list_answer');
- }
-
- /**
- * Finishes the session-id
- *
- * @return void
- */
- protected function finishSessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_request_node_list_answer');
- }
-
- /**
- * Finishes the 'request-node-list-answer'
- *
- * @return void
- */
- protected function finishRequestNodeListAnswer () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_request_node_list_answer');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * An ??? template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 Xml???TemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXml???TemplateEngine () {
- // Get a new instance
- $templateInstance = new Xml???TemplateEngine();
-
- // Init template instannce
- $templateInstance->initXmlTemplateEngine('PREFIX', '!!!');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return false;
- } // END - if
-
- // Assign data with matching variable here
- parent::assignVariable($this->getStackInstance()->getNamed('!!!'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function get???CacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the |||
- *
- * @return void
- */
- protected function start??? () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('!!!', '|||');
- }
-
- /**
- * Finishes the |||
- *
- * @return void
- */
- protected function finish??? () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('!!!');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A generic XML template engine class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 BaseXmlTemplateEngine extends BaseTemplateEngine {
- /**
- * Main nodes in the XML tree
- */
- private $mainNodes = array();
-
- /**
- * Sub nodes in the XML tree
- */
- private $subNodes = array();
-
- /**
- * Current main node
- */
- private $curr = array();
-
- /**
- * XML template type
- */
- private $xmlTemplateType = 'xml';
-
- /**
- * Type prefix
- */
- private $typePrefix = 'xml';
-
- /**
- * Name of stacker
- */
- private $stackerName = '';
-
- /**
- * Content from dependency
- */
- protected $dependencyContent = array();
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Does a generic initialization of the template engine
- *
- * @param $typePrefix Type prefix
- * @param $xmlTemplateType Type of XML template
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- protected function initXmlTemplateEngine ($typePrefix, $xmlTemplateType) {
- // Get template instance
- $applicationInstance = Registry::getRegistry()->getInstance('app');
-
- // Determine base path
- $templateBasePath = $this->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
-
- // Is the base path valid?
- if (empty($templateBasePath)) {
- // Base path is empty
- throw new BasePathIsEmptyException($this, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (!is_string($templateBasePath)) {
- // Is not a string
- throw new InvalidBasePathStringException(array($this, $templateBasePath), self::EXCEPTION_INVALID_STRING);
- } elseif (!is_dir($templateBasePath)) {
- // Is not a path
- throw new BasePathIsNoDirectoryException(array($this, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
- } elseif (!is_readable($templateBasePath)) {
- // Is not readable
- throw new BasePathReadProtectedException(array($this, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
- }
-
- // Set the base path
- $this->setTemplateBasePath($templateBasePath);
-
- // Set template extensions
- $this->setRawTemplateExtension($this->getConfigInstance()->getConfigEntry('raw_template_extension'));
- $this->setCodeTemplateExtension($this->getConfigInstance()->getConfigEntry($typePrefix . '_message_template_extension'));
-
- // Absolute output path for compiled templates
- $this->setCompileOutputPath($this->getConfigInstance()->getConfigEntry('base_path') . $this->getConfigInstance()->getConfigEntry('compile_output_path'));
-
- // Init a variable stacker
- $stackInstance = ObjectFactory::createObjectByConfiguredName($typePrefix . '_' . $xmlTemplateType . '_stacker_class');
-
- // Set name
- $this->stackerName = $typePrefix . '_' . $xmlTemplateType;
-
- // Init stacker
- $stackInstance->initStack($this->stackerName);
-
- // Set it
- $this->setStackInstance($stackInstance);
-
- // Set XML template type and prefix
- $this->xmlTemplateType = $xmlTemplateType;
- $this->typePrefix = $typePrefix;
-
- // Set it in main nodes
- array_push($this->mainNodes, str_replace('_', '-', $xmlTemplateType));
- }
-
- /**
- * Load a specified XML template into the engine
- *
- * @param $templateName Optional name of template
- * @return void
- */
- public function loadXmlTemplate ($templateName = '') {
- // Is the template name empty?
- if (empty($templateName)) {
- // Set generic template name
- $templateName = $this->typePrefix . '_' . $this->xmlTemplateType . '_template_type';
- } // END - if
-
- // Set template type
- $this->setTemplateType($this->getConfigInstance()->getConfigEntry($templateName));
-
- // Load the special template
- $this->loadTemplate($this->xmlTemplateType);
- }
-
- /**
- * Getter for current main node
- *
- * @return $currMainNode Current main node
- */
- public final function getCurrMainNode () {
- return $this->curr['main_node'];
- }
-
- /**
- * Setter for current main node
- *
- * @param $element Element name to set as current main node
- * @return $currMainNode Current main node
- */
- private final function setCurrMainNode ($element) {
- $this->curr['main_node'] = (string) $element;
- }
-
- /**
- * Getter for main node array
- *
- * @return $mainNodes Array with valid main node names
- */
- public final function getMainNodes () {
- return $this->mainNodes;
- }
-
- /**
- * Getter for stacker name
- *
- * @return $stackerName Name of stacker of this class
- */
- protected final function getStackerName () {
- return $this->stackerName;
- }
-
- /**
- * Setter for sub node array
- *
- * @param $subNodes Array with valid sub node names
- * @return void
- */
- public final function setSubNodes (array $subNodes) {
- $this->subNodes = $subNodes;
- }
-
- /**
- * Getter for sub node array
- *
- * @return $subNodes Array with valid sub node names
- */
- public final function getSubNodes () {
- return $this->subNodes;
- }
-
- /**
- * Read XML variables by calling readVariable() with 'general' as
- * variable stack.
- *
- * @param $key Key to read from
- * @return $value Value from variable
- */
- public function readXmlData ($key) {
- // Read the variable
- $value = parent::readVariable($key, 'general');
-
- // Is this null?
- if (is_null($value)) {
- // Bah, needs fixing.
- $this->debugInstance('key=' . $key . ' returns NULL');
- } // END - if
-
- // Return value
- return $value;
- }
-
- /**
- * Handles the template dependency for given XML node
- *
- * @param $node The XML node we should load a dependency template
- * @param $templateDependency A template to load to satisfy dependencies
- * @return void
- */
- protected function handleTemplateDependency ($node, $templateDependency) {
- // Check that the XML node is not empty
- assert(!empty($node));
-
- // Is the template dependency set?
- if ((!empty($templateDependency)) && (!isset($this->dependencyContent[$node]))) {
- // Get a temporay template instance
- $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance($this->typePrefix . '_' . self::convertDashesToUnderscores($node) . '_' . $this->xmlTemplateType . '_template_class');
-
- // Then load it
- $templateInstance->loadXmlTemplate($templateDependency);
-
- // Parse the XML content
- $templateInstance->renderXmlContent();
-
- // Save the parsed raw content in our dependency array
- $this->dependencyContent[$node] = $templateInstance->getRawTemplateData();
- } // END - if
- }
-
- /**
- * Handles the start element of an XML resource
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $element The element we shall handle
- * @param $attributes All attributes
- * @return void
- * @throws InvalidXmlNodeException If an unknown/invalid XML node name was found
- */
- public final function startElement ($resource, $element, array $attributes) {
- // Initial method name which will never be called...
- $methodName = 'init' . self::convertToClassName($this->xmlTemplateType);
-
- // Make the element name lower-case
- $element = strtolower($element);
-
- // Is the element a main node?
- //* DEBUG: */ echo "START: >".$element."<<br />\n";
- if (in_array($element, $this->getMainNodes())) {
- // Okay, main node found!
- $methodName = 'start' . self::convertToClassName($element);
-
- // Set it
- $this->setCurrMainNode($element);
- } elseif (in_array($element, $this->getSubNodes())) {
- // Sub node found
- $methodName = 'start' . self::convertToClassName($element);
- } else {
- // Invalid node name found
- throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
- }
-
- // Call method
- call_user_func_array(array($this, $methodName), $attributes);
- }
-
- /**
- * Ends the main or sub node by sending out the gathered data
- *
- * @param $resource An XML resource pointer (currently ignored)
- * @param $nodeName Name of the node we want to finish
- * @return void
- * @throws XmlNodeMismatchException If current main node mismatches the closing one
- */
- public final function finishElement ($resource, $nodeName) {
- // Make all lower-case
- $nodeName = strtolower($nodeName);
-
- // Does this match with current main node?
- //* DEBUG: */ echo "END: >".$nodeName."<<br />\n";
- if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
- // Did not match!
- throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH);
- } // END - if
-
- // Construct method name
- $methodName = 'finish' . self::convertToClassName($nodeName);
-
- // Call the corresponding method
- //* DEBUG: */ echo "call: ".$methodName."<br />\n";
- call_user_func_array(array($this, $methodName), array());
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An SelfConnect template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlSelfConnectTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Data nodes
- */
- const SELF_CONNECT_DATA_NODE_ID = 'node-id';
- const SELF_CONNECT_DATA_SESSION_ID = 'session-id';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->setSubNodes(array(
- 'self-connect-data',
- self::SELF_CONNECT_DATA_NODE_ID,
- self::SELF_CONNECT_DATA_SESSION_ID
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlSelfConnectTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlSelfConnectTemplateEngine();
-
- // Init template instance
- $templateInstance->initXmlTemplateEngine('node', 'self_connect');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- * @todo Find something useful with this!
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- /*
- * Assign the found characters to variable and use the last entry from
- * stack as the name
- */
- parent::assignVariable($this->getStackInstance()->getNamed('node_self_connect'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getMenuCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the self_connect
- *
- * @return void
- */
- protected function startSelfConnect () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_self_connect', 'self-connect');
- }
-
- /**
- * Starts the self_connect data
- *
- * @return void
- */
- protected function startSelfConnectData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_self_connect', 'self-connect-data');
- }
-
- /**
- * Starts the node id
- *
- * @return void
- */
- protected function startNodeId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_self_connect', self::SELF_CONNECT_DATA_NODE_ID);
- }
-
- /**
- * Starts the session id
- *
- * @return void
- */
- protected function startSessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_self_connect', self::SELF_CONNECT_DATA_SESSION_ID);
- }
-
- /**
- * Finishes the session id
- *
- * @return void
- */
- protected function finishSessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_self_connect');
- }
-
- /**
- * Finishes the node id
- *
- * @return void
- */
- protected function finishNodeId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_self_connect');
- }
-
- /**
- * Finishes the self_connect data
- *
- * @return void
- */
- protected function finishSelfConnectData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_self_connect');
- }
-
- /**
- * Finishes the self_connect
- *
- * @return void
- */
- protected function finishSelfConnect () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_self_connect');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An Bootstrap template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlDhtBootstrapTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Some XML nodes must be available for later data extraction
- */
- const DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA = 'dht-bootstrap-data';
- const DHT_BOOTSTRAP_DATA_SESSION_ID = 'session-id';
- const DHT_BOOTSTRAP_DATA_NODE_STATUS = 'node-status';
- const DHT_BOOTSTRAP_DATA_NODE_MODE = 'node-mode';
- const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'external-address';
- const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'internal-address';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->setSubNodes(array(
- self::DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA,
- 'listener',
- self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
- self::DHT_BOOTSTRAP_DATA_NODE_MODE,
- self::DHT_BOOTSTRAP_DATA_SESSION_ID,
- self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlDhtBootstrapTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlDhtBootstrapTemplateEngine();
-
- // Init template instance
- $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- /*
- * Assign the found characters to variable and use the last entry from
- * stack as the name.
- */
- parent::assignVariable($this->getStackInstance()->getNamed('dht_bootstrap'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getMenuCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the dht bootstrap
- *
- * @return void
- */
- protected function startDhtBootstrap () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_bootstrap', 'dht-bootstrap');
- }
-
- /**
- * Starts the dht bootstrap data
- *
- * @return void
- */
- protected function startDhtBootstrapData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA);
- }
-
- /**
- * Starts the node status
- *
- * @return void
- */
- protected function startNodeStatus () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
- }
-
- /**
- * Starts the node-mode
- *
- * @return void
- */
- protected function startNodeMode () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_MODE);
- }
-
- /**
- * Starts the listener
- *
- * @return void
- */
- protected function startListener () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_bootstrap', 'listener');
- }
-
- /**
- * Starts the public ip
- *
- * @return void
- */
- protected function startExternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS);
- }
-
- /**
- * Starts the private ip
- *
- * @return void
- */
- protected function startInternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS);
- }
-
- /**
- * Starts the session id
- *
- * @return void
- */
- protected function startSessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
- }
-
- /**
- * Finishes the session id
- *
- * @return void
- */
- protected function finishSessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_bootstrap');
- }
-
- /**
- * Finishes the private ip
- *
- * @return void
- */
- protected function finishInternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_bootstrap');
- }
-
- /**
- * Finishes the public ip
- *
- * @return void
- */
- protected function finishExternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_bootstrap');
- }
-
- /**
- * Finishes the listener
- *
- * @return void
- */
- protected function finishListener () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_bootstrap');
- }
-
- /**
- * Finishes the node mode
- *
- * @return void
- */
- protected function finishNodeMode () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_bootstrap');
- }
-
- /**
- * Finishes the node status
- *
- * @return void
- */
- protected function finishNodeStatus () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_bootstrap');
- }
-
- /**
- * Finishes the dht bootstrap data
- *
- * @return void
- */
- protected function finishDhtBootstrapData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_bootstrap');
- }
-
- /**
- * Finishes the dht bootstrap
- *
- * @return void
- */
- protected function finishDhtBootstrap () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_bootstrap');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An RequestNodeListEntry template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlRequestNodeListEntryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlRequestNodeListEntryTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlRequestNodeListEntryTemplateEngine();
-
- // Init template instannce
- $templateInstance->initXmlTemplateEngine('node', 'request_node_list_entry');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- * @todo Find something useful with this!
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- // Assign data with matching variable here
- parent::assignVariable($this->getStackInstance()->getNamed('node_request_node_list_entry'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getRequestNodeListEntryCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the request-node-list-entry
- *
- * @return void
- */
- protected function startRequestNodeListEntry () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_request_node_list_entry', 'request-node-list-entry');
- }
-
- /**
- * Finishes the request-node-list-entry
- *
- * @return void
- */
- protected function finishRequestNodeListEntry () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_request_node_list_entry');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An ObjectRegistry template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- // Constants
- const OBJECT_TYPE_DATA_NAME = 'object-name';
- const OBJECT_TYPE_DATA_RECIPIENT_LIMITATION = 'object-recipient-limitation';
- const OBJECT_TYPE_DATA_MAX_SPREAD = 'object-max-spread';
- const OBJECT_TYPE_DATA_PROTOCOL = 'object-protocol';
- const OBJECT_TYPE_DATA_RECIPIENT_TYPE = 'object-recipient-type';
-
- /**
- * Instance for the object registry
- */
- private $objectRegistryInstance = NULL;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init object type registry instance
- $this->objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
-
- // Init sub nodes
- $this->setSubNodes(array(
- 'object-list',
- 'object-list-entry',
- self::OBJECT_TYPE_DATA_NAME,
- self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION,
- self::OBJECT_TYPE_DATA_MAX_SPREAD,
- self::OBJECT_TYPE_DATA_PROTOCOL,
- self::OBJECT_TYPE_DATA_RECIPIENT_TYPE
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlObjectRegistryTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlObjectRegistryTemplateEngine();
-
- // Init template instance
- $templateInstance->initXmlTemplateEngine('node', 'object_registry');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- * @todo Find something useful with this!
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- // Get current XML node name as an array index
- $nodeName = $this->getStackInstance()->getNamed('node_object_registry');
-
- // Is the node name self::OBJECT_TYPE_DATA_NAME?
- if ($nodeName == self::OBJECT_TYPE_DATA_NAME) {
- // Output debug message
- self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Adding object type ' . $characters . ' to registry.');
- } // END - if
-
- // Add it to the registry
- $this->objectRegistryInstance->addEntry($nodeName, $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getObjectRegistryCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the object-registry
- *
- * @return void
- */
- protected function startObjectRegistry () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_object_registry', 'object-registry');
- }
-
- /**
- * Starts the object-list
- *
- * @param $objectCount Count of all objects
- * @return void
- * @todo Handle $objectCount
- */
- protected function startObjectList ($objectCount) {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_object_registry', 'object-list');
- }
-
- /**
- * Starts the object-list-entry
- *
- * @return void
- */
- protected function startObjectListEntry () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_object_registry', 'object-list-entry');
- }
-
- /**
- * Starts the object-name
- *
- * @return void
- */
- protected function startObjectName () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_NAME);
- }
-
- /**
- * Starts the object-recipient-limitation
- *
- * @return void
- */
- protected function startObjectRecipientLimitation () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION);
- }
-
- /**
- * Starts the object-max-spread
- *
- * @return void
- */
- protected function startObjectMaxSpread () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_MAX_SPREAD);
- }
-
- /**
- * Starts the object-protocol
- *
- * @return void
- */
- protected function startObjectProtocol () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_PROTOCOL);
- }
-
- /**
- * Starts the object-recipient-type
- *
- * @return void
- */
- protected function startObjectRecipientType () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_TYPE);
- }
-
- /**
- * Finishes the object-recipient-type
- *
- * @return void
- */
- protected function finishObjectRecipientType () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_object_registry');
- }
-
- /**
- * Finishes the object-protocol
- *
- * @return void
- */
- protected function finishObjectProtocol () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_object_registry');
- }
-
- /**
- * Finishes the object-max-spread
- *
- * @return void
- */
- protected function finishObjectMaxSpread () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_object_registry');
- }
-
- /**
- * Finishes the object-recipient-limitation
- *
- * @return void
- */
- protected function finishObjectRecipientLimitation () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_object_registry');
- }
-
- /**
- * Finishes the object-name
- *
- * @return void
- */
- protected function finishObjectName () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_object_registry');
- }
-
- /**
- * Finishes the object-list-entry
- *
- * @return void
- */
- protected function finishObjectListEntry () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_object_registry');
- }
-
- /**
- * Finishes the object-list
- *
- * @return void
- */
- protected function finishObjectList () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_object_registry');
- }
-
- /**
- * Finishes the object-registry
- *
- * @return void
- */
- protected function finishObjectRegistry () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_object_registry');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An TestUnit template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2011 - 2014 Cruncher Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlCruncherTestUnitTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init sub nodes
- $this->setSubNodes(array(
- 'meta-data',
- 'global-project-identifier',
- 'test-unit-created',
- 'cipher',
- 'cipher-function',
- 'cipher-name',
- 'unprocessed-data',
- 'encrypted-message',
- 'cruncher-key-list',
- 'cruncher-key',
- 'key-id',
- 'key-value'
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlCruncherTestUnitTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlCruncherTestUnitTemplateEngine();
-
- // Init template instance
- $templateInstance->initXmlTemplateEngine('cruncher', 'test_unit');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- // Assign the found characters to variable and use the last entry from
- // stack as the name
- parent::assignVariable($this->getStackInstance()->getNamed('cruncher_test_unit'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getCruncherTestUnitCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the test-unit
- *
- * @return void
- */
- protected function startTestUnit () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cruncher-test-unit');
- }
-
- /**
- * Starts the meta-data
- *
- * @return void
- */
- protected function startMetaData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'meta-data');
- }
-
- /**
- * Starts the global-project-identifier
- *
- * @return void
- */
- protected function startGlobalProjectIdentifier () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'global-project-identifier');
- }
-
- /**
- * Finishes the global-project-identifier
- *
- * @return void
- */
- protected function finishGlobalProjectIdentifier () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Starts the test-unit-created
- *
- * @return void
- */
- protected function startTestUnitCreated () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'test-unit-created');
- }
-
- /**
- * Finishes the test-unit-created
- *
- * @return void
- */
- protected function finishTestUnitCreated () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Starts the cipher
- *
- * @return void
- */
- protected function startCipher () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cipher');
- }
-
- /**
- * Starts the cipher-function
- *
- * @return void
- */
- protected function startCipherFunction () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cipher-function');
- }
-
- /**
- * Finishes the cipher-function
- *
- * @return void
- */
- protected function finishCipherFunction () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Starts the cipher-name
- *
- * @return void
- */
- protected function startCipherName () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cipher-name');
- }
-
- /**
- * Finishes the cipher-name
- *
- * @return void
- */
- protected function finishCipherName () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Finishes the cipher
- *
- * @return void
- */
- protected function finishCipher () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Finishes the meta-data
- *
- * @return void
- */
- protected function finishMetaData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Starts the unprocessed-data
- *
- * @return void
- */
- protected function startUnprocessedData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'unprocessed-data');
- }
-
- /**
- * Starts the encrypted-message
- *
- * @return void
- */
- protected function startEncryptedMessage () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'encrypted-message');
- }
-
- /**
- * Finishes the encrypted-message
- *
- * @return void
- */
- protected function finishEncryptedMessage () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Starts the cruncher-key-list
- *
- * @param $keyCount Count of keys in this test unit
- * @return void
- * @todo Handle $keyCount
- */
- protected function startCruncherKeyList ($keyCount) {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cruncher-key-list');
- }
-
- /**
- * Starts the cruncher-key
- *
- * @return void
- */
- protected function startCruncherKey () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'cruncher-key');
- }
-
- /**
- * Starts the key-id
- *
- * @return void
- */
- protected function startKeyId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'key-id');
- }
-
- /**
- * Finishes the key-id
- *
- * @return void
- */
- protected function finishKeyId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Starts the key-value
- *
- * @return void
- */
- protected function startKeyValue () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('cruncher_test_unit', 'key-value');
- }
-
- /**
- * Finishes the key-value
- *
- * @return void
- */
- protected function finishKeyValue () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Finishes the cruncher-key
- *
- * @return void
- */
- protected function finishCruncherKey () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Finishes the cruncher-key-list
- *
- * @return void
- */
- protected function finishCruncherKeyList () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Finishes the unprocessed-data
- *
- * @return void
- */
- protected function finishUnprocessedData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-
- /**
- * Finishes the test-unit
- *
- * @return void
- */
- protected function finishTestUnit () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('cruncher_test_unit');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An PublishEntry template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlDhtPublishEntryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- /**
- * Some XML nodes must be available for later data extraction
- */
- const PUBLISH_DATA_NODE_ID = 'node-id';
- const PUBLISH_DATA_SESSION_ID = 'session-id';
- const PUBLISH_DATA_NODE_STATUS = 'node-status';
- const PUBLISH_DATA_NODE_MODE = 'node-mode';
- const PUBLISH_DATA_EXTERNAL_ADDRESS = 'external-address';
- const PUBLISH_DATA_PRIVATE_KEY_HASH = 'private-key-hash';
- const PUBLISH_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->setSubNodes(array(
- 'publish-data',
- 'listener',
- self::PUBLISH_DATA_NODE_STATUS,
- self::PUBLISH_DATA_NODE_MODE,
- self::PUBLISH_DATA_PRIVATE_KEY_HASH,
- self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES,
- self::PUBLISH_DATA_NODE_ID,
- self::PUBLISH_DATA_SESSION_ID,
- self::PUBLISH_DATA_EXTERNAL_ADDRESS,
- 'object-type-list',
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlDhtPublishEntryTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlDhtPublishEntryTemplateEngine();
-
- // Init template instance
- $templateInstance->initXmlTemplateEngine('node', 'dht_publish');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- /*
- * Assign the found characters to variable and use the last entry from
- * stack as the name.
- */
- parent::assignVariable($this->getStackInstance()->getNamed('dht_publish'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getMenuCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the publish
- *
- * @return void
- */
- protected function startPublish () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', 'publish');
- }
-
- /**
- * Starts the publish data
- *
- * @return void
- */
- protected function startPublishData () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', 'publish-data');
- }
-
- /**
- * Starts the node status
- *
- * @return void
- */
- protected function startNodeStatus () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_STATUS);
- }
-
- /**
- * Starts the node-mode
- *
- * @return void
- */
- protected function startNodeMode () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_MODE);
- }
-
- /**
- * Starts the listener
- *
- * @return void
- */
- protected function startListener () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', 'listener');
- }
-
- /**
- * Starts accepted object types
- *
- * @return void
- */
- protected function startAcceptedObjectTypes () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES);
- }
-
- /**
- * Starts hash from private key
- *
- * @return void
- */
- protected function startPrivateKeyHash () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_PRIVATE_KEY_HASH);
- }
-
- /**
- * Starts the node id
- *
- * @return void
- */
- protected function startNodeId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_ID);
- }
-
- /**
- * Starts the session id
- *
- * @return void
- */
- protected function startSessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_SESSION_ID);
- }
-
- /**
- * Starts the public ip
- *
- * @return void
- */
- protected function startExternalAddress () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_EXTERNAL_ADDRESS);
- }
-
- /**
- * Starts the object type list
- *
- * @return void
- */
- protected function startObjectTypeList () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', 'object-type-list');
- }
-
- /**
- * Starts the object type
- *
- * @return void
- */
- protected function startObjectType () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', 'object-type');
- }
-
- /**
- * Finishes the object type
- *
- * @return void
- */
- protected function finishObjectType () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes the object type list
- *
- * @return void
- */
- protected function finishObjectTypeList () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes the session id
- *
- * @return void
- */
- protected function finishSessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes the node id
- *
- * @return void
- */
- protected function finishNodeId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes the public ip
- *
- * @return void
- */
- protected function finishExternalAddress () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes hash from private key
- *
- * @return void
- */
- protected function finishPrivateKeyHash () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes accepted object types
- *
- * @return void
- */
- protected function finishAcceptedObjectTypes () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes the listener
- *
- * @return void
- */
- protected function finishListener () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes the node mode
- *
- * @return void
- */
- protected function finishNodeMode () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes the node status
- *
- * @return void
- */
- protected function finishNodeStatus () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes the publish data
- *
- * @return void
- */
- protected function finishPublishData () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
- /**
- * Finishes the publish
- *
- * @return void
- */
- protected function finishPublish () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An ??? template engine class for XML templates
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- * @todo This template engine does not make use of setTemplateType()
- *
- * 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 XmlRequestNodeListTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
- // Constants for array elements
- const REQUEST_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types';
- const REQUEST_DATA_SESSION_ID = 'session-id';
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init sub nodes
- $this->setSubNodes(array(
- self::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
- self::REQUEST_DATA_SESSION_ID,
- ));
- }
-
- /**
- * Creates an instance of the class TemplateEngine and prepares it for usage
- *
- * @return $templateInstance An instance of TemplateEngine
- * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
- * @throws InvalidBasePathStringException If $templateBasePath is no string
- * @throws BasePathIsNoDirectoryException If $templateBasePath is no
- * directory or not found
- * @throws BasePathReadProtectedException If $templateBasePath is
- * read-protected
- */
- public static final function createXmlRequestNodeListTemplateEngine () {
- // Get a new instance
- $templateInstance = new XmlRequestNodeListTemplateEngine();
-
- // Init template instance
- $templateInstance->initXmlTemplateEngine('node', 'request_node_list');
-
- // Return the prepared instance
- return $templateInstance;
- }
-
- /**
- * Currently not used
- *
- * @param $resource XML parser resource (currently ignored)
- * @param $characters Characters to handle
- * @return void
- * @todo Find something useful with this!
- */
- public function characterHandler ($resource, $characters) {
- // Trim all spaces away
- $characters = trim($characters);
-
- // Is this string empty?
- if (empty($characters)) {
- // Then skip it silently
- return;
- } // END - if
-
- // Assign data with matching variable here
- parent::assignVariable($this->getStackInstance()->getNamed('node_request_node_list'), $characters);
- }
-
- /**
- * Getter for cache file (FQFN)
- *
- * @return $fqfn Full-qualified file name of the menu cache
- */
- public function getRequestNodeListCacheFqfn () {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Starts the node-request-node-list
- *
- * @return void
- */
- protected function startRequestNodeList () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_request_node_list', 'node-request-node-list');
- }
-
- /**
- * Starts the accepted-object-types
- *
- * @return void
- */
- protected function startAcceptedObjectTypes () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_request_node_list', self::REQUEST_DATA_ACCEPTED_OBJECT_TYPES);
- }
-
- /**
- * Starts the session-id
- *
- * @return void
- */
- protected function startSessionId () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_request_node_list', self::REQUEST_DATA_SESSION_ID);
- }
-
- /**
- * Finishes the session-id
- *
- * @return void
- */
- protected function finishSessionId () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_request_node_list');
- }
-
- /**
- * Finishes the accepted-object-types
- *
- * @return void
- */
- protected function finishAcceptedObjectTypes () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_request_node_list');
- }
-
- /**
- * Finishes the node-request-node-list
- *
- * @return void
- */
- protected function finishRequestNodeList () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_request_node_list');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * This class contains static helper functions for our hub
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HubTools extends BaseHubSystem {
- // Constants for exceptions
- const EXCEPTION_SESSION_ID_IS_INVALID = 0x200;
- const EXCEPTION_HOSTNAME_NOT_FOUND = 0x201;
-
- /**
- * Cache for session ids
- */
- private $sessionIdCache = array();
-
- /**
- * Length for session id (should be 32+salt_length
- */
- private $sessionIdLength = 0;
-
- /**
- * Self instance
- */
- private static $selfInstance = NULL;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set it here
- $this->setDhtInstance($dhtInstance);
-
- // Init salt length
- $this->sessionIdLength = 32 + $this->getConfigInstance()->getConfigEntry('salt_length');
- }
-
- /**
- * Singleton getter for self instance
- *
- * @retuen $selfInstance An instance of this class
- */
- public static final function getSelfInstance () {
- // Is the instance set
- if (is_null(self::$selfInstance)) {
- // Then set it
- self::$selfInstance = new HubTools();
- } // END - if
-
- // Return own instance
- return self::$selfInstance;
- }
-
- /**
- * Getter for session id length
- *
- * @return $sessionIdLength Length of session ids
- */
- protected final function getSessionIdLength () {
- return $this->sessionIdLength;
- }
-
- /**
- * Resolves a session id into an instance of a LocateableNode class. The opposite method
- * is resolveSessionIdByUniversalNodeLocator()
- *
- * @param $sessionId A valid session id
- * @return $recipientUniversalNodeLocator Recipient as Universal Node Locator
- */
- protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
- // Init variable
- $recipientUniversalNodeLocator = 'invalid://invalid:invalid';
-
- // And ask it for Universal Node Locator by given session id
- $recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId);
- //* DEBUG-DIE: */ die(__METHOD__ . ': UNFINISHED: recipient[' . gettype($recipient) . ']=' . print_r($recipient, TRUE) . ',sessionId=' . $sessionId . PHP_EOL);
-
- // Is the recipient valid?
- if (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS])) {
- // Then use this
- $recipientUniversalNodeLocator = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS];
- } else {
- // Get the instance, this might throw a NPE
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Is the session id the same?
- if ($nodeInstance->getSessionId() == $sessionId) {
- // Then get an instance of a LocateableNode class from it, assume TCP by default
- $recipientUniversalNodeLocator = self::determineOwnExternalAddress() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
- } // END - if
- }
-
- // Return result
- return $recipientUniversalNodeLocator;
- }
-
- /**
- * Resolves a session id into a node id by asking local DHT.
- *
- * @param $sessionId Session id
- * @return $nodeId Node id
- */
- public static function resolveNodeIdBySessionId ($sessionId) {
- // Get an own instance
- $selfInstance = self::getSelfInstance();
-
- // And ask it for session id by given Universal Node Locator
- $nodeData = $selfInstance->getDhtInstance()->findNodeLocalBySessionId($sessionId);
-
- // Make sure the node id is there
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ', nodeData[' . gettype($nodeData) . ']=' . print_r($nodeData, TRUE));
- assert(isset($nodeData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_NODE_ID]));
-
- // Return it
- return $nodeData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_NODE_ID];
- }
-
- /**
- * Resolves a Universal Node Locator into a session id. The "opposite" method
- * is resolveUniversalNodeLocatorBySessionId().
- *
- * @param $unlInstance Universal Node Locator
- * @return $sessionId Valid session id
- */
- public static function resolveSessionIdByUniversalNodeLocator (LocateableNode $unlInstance) {
- // Get an own instance
- $selfInstance = self::getSelfInstance();
-
- // And ask it for session id by given Universal Node Locator
- $recipient = $selfInstance->getDhtInstance()->findNodeByUniversalNodeLocator($unlInstance);
- die(__METHOD__.':recipient='.print_r($recipient, TRUE));
-
- // Return result
- return $sessionId;
- }
-
- /**
- * Resolves given session id into an instance of a LocateableNode class, if Universal Node Locator is set, it won't be translated
- *
- * @param $address Session id or Universal Node Locator
- * @return $recipient Recipient as Universal Node Locator
- * @throws InvalidSessionIdException If the provided session id is invalid (and no Universal Node Locator)
- * @throws NoValidHostnameException If the provided hostname cannot be resolved into an IP address
- */
- public static function resolveSessionId ($address) {
- // Get an own instance
- $selfInstance = self::getSelfInstance();
-
- // Default is direct Universal Node Locator
- $recipient = $address;
-
- // Does it match a direct Universal Node Locator? (hint: see www.regexlib.com for the regular expression)
- if (preg_match('/([a-z0-9]{3,10})\/\/:([a-z0-9\.]{5,})/', $address)) {
- // @TODO ((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})
- // Direct Universal Node Locator found
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Direct Universal Node Locator ' . $address . ' detected.');
- } elseif (isset($selfInstance->sessionIdCache[$address])) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using entry from sessionIdCache[] array.');
-
- // Found in cache!
- $recipient = $selfInstance->sessionIdCache[$address];
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: sessionIdCache[' . $address . ']=' . $recipient);
- } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $address)) {
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using internal session id resolver.');
-
- // Resolve session id into an instance of a LocateableNode class
- $recipient = $selfInstance->resolveUniversalNodeLocatorBySessionId($address);
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Session id ' . $address . ' resolved to ' . $recipient);
- } else {
- // Invalid session id/UNL
- throw new InvalidSessionIdException($address, self::EXCEPTION_SESSION_ID_IS_INVALID);
- }
-
- // Return it
- return $recipient;
- }
-
- /**
- * Determine UNL or 'external_address' if set
- *
- * @return $unl The determined external UNL of this node
- */
- public static function determineOwnExternalAddress () {
- // Is the external_address config entry set?
- if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address') != '') {
- // Use it as external address
- $unl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address');
- } else {
- // Determine own external address by connecting to my (coder) server at 188.138.90.169
- $unl = self::determineExternalUniversalNodeLocator();
- }
-
- // Return it
- return $unl;
- }
-
- /**
- * Determine UNL or 'internal_address' if set
- *
- * @return $unl The determined internal UNL of this node
- */
- public static function determineOwnInternalAddress () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Is the internal_address config entry set?
- if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Calling self::determineOwnExternalAddress() as allow_publish_internal_address=N is set ...');
-
- // Not allowed to publish internal address, so use external
- $unl = self::determineOwnExternalAddress();
- } elseif (FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address') != '') {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Getting config entry internal_address ...');
-
- // Use it as internal address
- $unl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address');
- } else {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Calling self::determineInternalUniversalNodeLocator() ...');
-
- // Determine own internal address
- $unl = self::determineInternalUniversalNodeLocator();
- }
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ' - EXIT!');
-
- // Return it
- return $unl;
- }
-
- /**
- * Determines the UNL (Universal Node Locator) for the internal address
- *
- * @return $internalUnl Internal UNL
- */
- public static function determineInternalUniversalNodeLocator () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Is there cache? (This shortens a lot calls)
- if (!isset($GLOBALS[__METHOD__])) {
- // Determine UNL based on this node:
- // 1) Get discovery class
- $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
-
- // 2) "Determine" it
- $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('internal');
-
- // Make sure it is valid
- // @TODO Find a better validation than empty()
- assert(!empty($GLOBALS[__METHOD__]));
- } // END - if
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
- return $GLOBALS[__METHOD__];
- }
-
- /**
- * Determines the UNL (Universal Node Locator) for the external address
- *
- * @return $externalUnl External UNL
- */
- public static function determineExternalUniversalNodeLocator () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Is there cache? (This shortens a lot calls)
- if (!isset($GLOBALS[__METHOD__])) {
- // Determine UNL based on this node:
- // 1) Get discovery class
- $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
-
- // 2) "Determine" it
- $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('external');
-
- // Make sure it is valid
- // @TODO Find a better validation than empty()
- assert(!empty($GLOBALS[__METHOD__]));
- } // END - if
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
- return $GLOBALS[__METHOD__];
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A UniversalNodeLocator
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 UniversalNodeLocator extends BaseFrameworkSystem implements LocateableNode {
- //------- UNL parts -------
- // Protocol
- const UNL_PART_PROTOCOL = 'protocol';
- // Address
- const UNL_PART_ADDRESS = 'address';
- // Extra part
- const UNL_PART_EXTRA = 'extra';
- // Port (if any)
- const UNL_PART_PORT = 'port';
-
- /**
- * UNL data array
- */
- private $unlData = array();
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
- * @return $unlInstance An instance of a LocateableNode class
- */
- public final static function createUniversalNodeLocator (array $current = array()) {
- // Get new instance
- $unlInstance = new UniversalNodeLocator();
-
- // Init instance
- $unlInstance->initUniversalNodeLocator($current);
-
- // Return the prepared instance
- return $unlInstance;
- }
-
- /**
- * Initializes the UNL instance by givena array. If an entry is found, it
- * will be copied, otherwise the entry is set empty.
- *
- * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
- * @return void
- */
- private function initUniversalNodeLocator (array $current = array()) {
- // Init UNL array
- $this->unlData = array();
-
- // Copy all found entries
- foreach (array(
- NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID,
- NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID,
- NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH,
- NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE,
- NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL,
- NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) {
- // Init entry
- $this->unlData[$key] = NULL;
-
- // Is the key found?
- if (isset($current[$key])) {
- // The copy the entry
- $this->unlData[$key] = $current[$key];
- } // END - if
- } // END - foreach
- }
-
- /**
- * Getter for UNL data array
- *
- * @return $unlData An array with UNL data
- */
- public final function getUnlData () {
- return $this->unlData;
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? visitor
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 ???Visitor extends BaseVisitor implements PoolVisitor {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set visitor mode
- $this->setVisitorMode('???');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $visitorInstance An instance a Visitorable class
- */
- public final static function create???Visitor () {
- // Get new instance
- $visitorInstance = new ???Visitor();
-
- // Return the prepared instance
- return $visitorInstance;
- }
-
- /**
- * Visits the given pool instance
- *
- * @param $poolInstance A Poolable instance
- * @return void
- * @todo 0%
- */
- public function visitPool (Poolable $poolInstance) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? handler visitor
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Handler???Visitor extends BaseVisitor implements PoolVisitor {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set visitor mode
- $this->setVisitorMode('handler');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $visitorInstance An instance a Visitorable class
- */
- public final static function createHandler???Visitor () {
- // Get new instance
- $visitorInstance = new Handler???Visitor();
-
- // Return the prepared instance
- return $visitorInstance;
- }
-
- /**
- * Visits the given pool instance
- *
- * @param $poolInstance A Poolable instance
- * @return void
- * @todo 0%
- */
- public function visitPool (Poolable $poolInstance) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A RawDataMonitor visitor
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 RawDataPoolMonitorVisitor extends BaseVisitor implements PoolVisitor, ListenerVisitor {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set visitor mode
- $this->setVisitorMode('monitor');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $receiverInstance An instance of a Receivable class
- * @return $visitorInstance An instance of a Visitorable class
- */
- public final static function createRawDataPoolMonitorVisitor () {
- // Get new instance
- $visitorInstance = new RawDataPoolMonitorVisitor();
-
- // Return the prepared instance
- return $visitorInstance;
- }
-
- /**
- * Visits the given pool instance
- *
- * @param $poolInstance A Poolable instance
- * @return void
- */
- public function visitPool (Poolable $poolInstance) {
- // A pool doesn't normally have any raw data waiting
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: poolInstance=' . $poolInstance->__toString() . ' - CALLED!');
- }
-
- /**
- * Visits the given listener instance
- *
- * @param $listenerInstance A Listenable instance
- * @return void
- */
- public function visitListener (Listenable $listenerInstance) {
- /*
- * The listener itself cannot distinguish between node and client
- * traffic. This is why we don't call its monitorIncomingRawData()
- * method.
- */
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: listenerInstance=' . $listenerInstance->__toString() . ' - CALLED!');
- }
-
- /**
- * Visits the given decorator instance
- *
- * @param $decoratorInstance A decorator instance
- * @return void
- */
- public function visitDecorator (BaseDecorator $decoratorInstance) {
- // Do monitor here
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - CALLED!');
- $decoratorInstance->monitorIncomingRawData();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visiting ' . $listenerInstance->__toString() . ' - FINISH');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A ??? shutdown visitor
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub; Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.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 Shutdown???Visitor extends BaseVisitor implements PoolVisitor {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set visitor mode
- $this->setVisitorMode('shutdown');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $visitorInstance An instance a Visitorable class
- */
- public final static function createShutdown???Visitor () {
- // Get new instance
- $visitorInstance = new Shutdown???Visitor();
-
- // Return the prepared instance
- return $visitorInstance;
- }
-
- /**
- * Visits the given pool instance
- *
- * @param $poolInstance A Poolable instance
- * @return void
- * @todo 0%
- */
- public function visitPool (Poolable $poolInstance) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ListenerPool shutdown visitor
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ShutdownListenerPoolVisitor extends BaseVisitor implements PoolVisitor {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set visitor mode
- $this->setVisitorMode('shutdown');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $visitorInstance An instance a Visitorable class
- */
- public static final function createShutdownListenerPoolVisitor () {
- // Get new instance
- $visitorInstance = new ShutdownListenerPoolVisitor();
-
- // Return the prepared instance
- return $visitorInstance;
- }
-
- /**
- * Visits the given pool instance
- *
- * @param $poolInstance A Poolable instance
- * @return void
- */
- public function visitPool (Poolable $poolInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $poolInstance->__toString() . ' - CALLED!');
-
- // Pre-shutdown the pool
- $poolInstance->preShutdown();
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $poolInstance->__toString() . ' - EXIT!');
- }
-
- /**
- * Visits the given decorator instance
- *
- * @param $decoratorInstance A Listenable decorator instance
- * @return void
- */
- public function visitDecorator (Listenable $decoratorInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $decoratorInstance->__toString() . ' - CALLED!');
-
- // Pre-shutdown the pool
- $decoratorInstance->doShutdown();
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $decoratorInstance->__toString() . ' - EXIT!');
- }
-
- /**
- * Visits the given listener instance
- *
- * @param $listenerInstance A Listenable class instance
- * @return void
- */
- public function visitListener (Listenable $listenerInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $listenerInstance->__toString() . ' - CALLED!');
-
- // Pre-shutdown the pool
- $listenerInstance->doShutdown();
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ' ]: Visit of ' . $listenerInstance->__toString() . ' - EXIT!');
- }
-}
-
-//
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A HalfShutdownSocket visitor
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 HalfShutdownSocketVisitor extends BaseVisitor implements Visitor {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set visitor mode
- $this->setVisitorMode('socket');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $visitorInstance An instance a Visitorable class
- */
- public static final function createHalfShutdownSocketVisitor () {
- // Get new instance
- $visitorInstance = new HalfShutdownSocketVisitor();
-
- // Return the prepared instance
- return $visitorInstance;
- }
-
- /**
- * "Visit" method to do the actual request. Here we want to shutdown the
- * attached socket.
- *
- * @param $helperInstance An instance of a ConnectionHelper class
- * @return void
- */
- public function visitConnectionHelper (ConnectionHelper $helperInstance) {
- // Do we have reached the retry count?
- if (ConnectionStatisticsHelper::isConnectRetryExhausted($helperInstance)) {
- // Also visit the network package to clear any out-going packages
- NetworkPackageFactory::createNetworkPackageInstance()->accept($this);
-
- // Still shutdown the visitor (look in visitNetworkPackage() for details)
- $helperInstance->doShutdown();
- } else {
- // We can still move on and retry the connection attempt
- ConnectionStatisticsHelper::increaseConnectRetry($helperInstance);
- }
- }
-
- /**
- * "Visit" method to do the actual request. This method does remove the last
- * failed package from the stack because all retries are fully exhausted
- * (see visitConnectionHelper() for the logic).
- *
- * @param $packageInstance An instance of a Deliverable class
- * @return void
- */
- public function visitNetworkPackage (Deliverable $packageInstance) {
- // Just call it back
- $packageInstance->removeFirstFailedPackage();
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ShutdownSocket visitor
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ShutdownSocketVisitor extends BaseVisitor implements Visitor {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set visitor mode
- $this->setVisitorMode('socket');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $visitorInstance An instance a Visitorable class
- */
- public static final function createShutdownSocketVisitor () {
- // Get new instance
- $visitorInstance = new ShutdownSocketVisitor();
-
- // Return the prepared instance
- return $visitorInstance;
- }
-
- /**
- * "Visit" method to do the actual request. Here we want to shutdown the
- * attached socket.
- *
- * @param $helperInstance An instance of a ConnectionHelper class
- * @return void
- */
- public function visitConnectionHelper (ConnectionHelper $helperInstance) {
- // Do we have reached the retry count?
- if (ConnectionStatisticsHelper::isConnectRetryExhausted($helperInstance)) {
- // Also visit the network package to clear any out-going packages
- NetworkPackageFactory::createNetworkPackageInstance()->accept($this);
-
- // Shutdown the connection
- $helperInstance->doShutdown();
- } else {
- // We can still move on and retry the connection attempt
- ConnectionStatisticsHelper::increaseConnectRetry($helperInstance);
- }
- }
-
- /**
- * "Visit" method to do the actual request. Here we want to "partly shutdown"
- * the network package instance to clear all stacks.
- *
- * @param $packageInstance An instance of a Deliverable class
- * @return void
- */
- public function visitNetworkPackage (Deliverable $packageInstance) {
- // Just call it back
- $packageInstance->clearAllStacks();
- }
-
- /**
- * "Visit" the assembler instance. This shall clear any pending data
- *
- * @param $assemblerInstance An instance of a Assembler class
- * @return void
- */
- public function visitAssembler (Assembler $assemblerInstance) {
- // Clear pending data
- $assemblerInstance->clearPendingData();
- }
-}
-
-// [EOF]
-?>
-Subproject commit 17f36438ae9e5d239cbfc019890ea81ba5f00bb1
+Subproject commit 7bc4014657a70dedfc38b9b28d134aa7c3a6158c