3 * A general hub system class
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class BaseHubSystem extends BaseFrameworkSystem {
26 const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x900;
27 const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0x901;
28 const EXCEPTION_INVALID_CONNECTION_TYPE = 0x902;
29 const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED = 0x903;
30 const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4 = 0x904;
31 const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0x905;
32 const EXCEPTION_REQUEST_NOT_ACCEPTED = 0x906;
33 const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED = 0x907;
34 const EXCEPTION_MULTIPLE_MESSAGE_SENT = 0x908;
35 const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED = 0x909;
36 const EXCEPTION_INVALID_UNL = 0x90a;
37 const EXCEPTION_INVALID_PRIVATE_KEY_HASH = 0x90b;
39 // Message status codes
40 const MESSAGE_STATUS_CODE_OKAY = 'OKAY';
43 * Separator for all bootstrap node entries
45 const BOOTSTRAP_NODES_SEPARATOR = ';';
48 * An instance of a node
50 private $nodeInstance = NULL;
53 * A network package handler instance
55 private $packageInstance = NULL;
58 * A Receivable instance
60 private $receiverInstance = NULL;
63 * Listener pool instance
65 private $listenerPoolInstance = NULL;
70 private $fragmenterInstance = NULL;
75 private $assemblerInstance = NULL;
80 private $infoInstance = NULL;
83 * Protected constructor
85 * @param $className Name of the class
88 protected function __construct ($className) {
89 // Call parent constructor
90 parent::__construct($className);
94 * Setter for network package handler instance
96 * @param $packageInstance The network package instance we shall set
99 protected final function setPackageInstance (Deliverable $packageInstance) {
100 $this->packageInstance = $packageInstance;
104 * Getter for network package handler instance
106 * @return $packageInstance The network package handler instance we shall set
108 protected final function getPackageInstance () {
109 return $this->packageInstance;
113 * Setter for receiver instance
115 * @param $receiverInstance A Receivable instance we shall set
118 protected final function setReceiverInstance (Receivable $receiverInstance) {
119 $this->receiverInstance = $receiverInstance;
123 * Getter for receiver instance
125 * @return $receiverInstance A Receivable instance we shall get
127 protected final function getReceiverInstance () {
128 return $this->receiverInstance;
132 * Setter for listener pool instance
134 * @param $listenerPoolInstance The new listener pool instance
137 protected final function setListenerPoolInstance (PoolableListener $listenerPoolInstance) {
138 $this->listenerPoolInstance = $listenerPoolInstance;
142 * Getter for listener pool instance
144 * @return $listenerPoolInstance Our current listener pool instance
146 public final function getListenerPoolInstance () {
147 return $this->listenerPoolInstance;
151 * Setter for fragmenter instance
153 * @param $fragmenterInstance A Fragmentable instance
156 protected final function setFragmenterInstance (Fragmentable $fragmenterInstance) {
157 $this->fragmenterInstance = $fragmenterInstance;
161 * Getter for fragmenter instance
163 * @return $fragmenterInstance A Fragmentable instance
165 protected final function getFragmenterInstance () {
166 return $this->fragmenterInstance;
170 * Setter for assembler instance
172 * @param $assemblerInstance An instance of an Assembler class
175 protected final function setAssemblerInstance (Assembler $assemblerInstance) {
176 $this->assemblerInstance = $assemblerInstance;
180 * Getter for assembler instance
182 * @return $assemblerInstance An instance of an Assembler class
184 protected final function getAssemblerInstance () {
185 return $this->assemblerInstance;
189 * Setter for info instance
191 * @param $infoInstance A ShareableInfo instance
194 protected final function setInfoInstance (ShareableInfo $infoInstance) {
195 $this->infoInstance = $infoInstance;
199 * Getter for info instance
201 * @return $infoInstance An instance of a ShareableInfo class
203 public final function getInfoInstance () {
204 return $this->infoInstance;
210 * @param $nodeId The new node id
213 protected final function setNodeId ($nodeId) {
215 $this->getConfigInstance()->setConfigEntry('node_id', (string) $nodeId);
221 * @return $nodeId Current node id
223 public final function getNodeId () {
224 // Get it from config
225 return $this->getConfigInstance()->getConfigEntry('node_id');
229 * Setter for private key
231 * @param $privateKey The new private key
234 protected final function setPrivateKey ($privateKey) {
236 $this->getConfigInstance()->setConfigEntry('private_key', (string) $privateKey);
240 * Getter for private key
242 * @return $privateKey Current private key
244 public final function getPrivateKey () {
245 // Get it from config
246 return $this->getConfigInstance()->getConfigEntry('private_key');
250 * Setter for private key hash
252 * @param $privateKeyHash The new private key hash
255 protected final function setPrivateKeyHash ($privateKeyHash) {
257 $this->getConfigInstance()->setConfigEntry('private_key_hash', (string) $privateKeyHash);
261 * Getter for private key hash
263 * @return $privateKeyHash Current private key hash
265 public final function getPrivateKeyHash () {
266 // Get it from config
267 return $this->getConfigInstance()->getConfigEntry('private_key_hash');
271 * Setter for session id
273 * @param $sessionId The new session id
276 protected final function setSessionId ($sessionId) {
277 $this->getConfigInstance()->setConfigEntry('session_id', (string) $sessionId);
281 * Getter for session id
283 * @return $sessionId Current session id
285 public final function getSessionId () {
286 return $this->getConfigInstance()->getConfigEntry('session_id');