1 | <?php |
||
29 | class Client |
||
30 | { |
||
31 | use UseTimerTrait; |
||
32 | |||
33 | /** |
||
34 | * @var LoopInterface |
||
35 | */ |
||
36 | protected $loop; |
||
37 | |||
38 | /** |
||
39 | * @var Dispatcher |
||
40 | */ |
||
41 | protected $dispatcher; |
||
42 | |||
43 | /** |
||
44 | * @var Connector |
||
45 | */ |
||
46 | protected $connector; |
||
47 | |||
48 | /** |
||
49 | * Tunnels collection |
||
50 | * @var TunnelCollection |
||
51 | */ |
||
52 | protected $tunnels; |
||
53 | |||
54 | /** |
||
55 | * @var ConnectionInterface |
||
56 | */ |
||
57 | protected $controlConnection; |
||
58 | |||
59 | /** |
||
60 | * @var TunnelClientCollection |
||
61 | */ |
||
62 | protected $tunnelClients; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $serverAddress; |
||
68 | |||
69 | /** |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $credential; |
||
73 | |||
74 | /** |
||
75 | * @var string |
||
76 | */ |
||
77 | protected $id; |
||
78 | |||
79 | /** |
||
80 | * Auth info |
||
81 | * @var array |
||
82 | */ |
||
83 | protected $auth; |
||
84 | |||
85 | /** |
||
86 | * @var Logger |
||
87 | */ |
||
88 | protected $logger; |
||
89 | |||
90 | public function __construct($serverAddress, $tunnels, $auth, LoopInterface $loop = null, Dispatcher $dispatcher = null) |
||
100 | |||
101 | /** |
||
102 | * Creates array of tunnels |
||
103 | * @param array $data |
||
104 | * @return TunnelCollection |
||
105 | */ |
||
106 | protected function createTunnels($data) |
||
115 | |||
116 | /** |
||
117 | * Run the client |
||
118 | * @codeCoverageIgnore |
||
119 | */ |
||
120 | public function run() |
||
139 | |||
140 | /** |
||
141 | * Close the client |
||
142 | * @codeCoverageIgnore |
||
143 | */ |
||
144 | public function close() |
||
157 | |||
158 | /** |
||
159 | * Handles the control connection |
||
160 | * @param ConnectionInterface $connection |
||
161 | * @codeCoverageIgnore |
||
162 | */ |
||
163 | protected function handleControlConnection(ConnectionInterface $connection) |
||
187 | |||
188 | /** |
||
189 | * If the client disconnect from the server |
||
190 | * @codeCoverageIgnore |
||
191 | */ |
||
192 | public function handleDisconnectServer() |
||
197 | |||
198 | /** |
||
199 | * Request for auth |
||
200 | * @param ConnectionInterface $connection |
||
201 | * @codeCoverageIgnore |
||
202 | */ |
||
203 | protected function requestAuth(ConnectionInterface $connection) |
||
211 | |||
212 | /** |
||
213 | * Gets the client id |
||
214 | * @return string |
||
215 | */ |
||
216 | public function getClientId() |
||
220 | |||
221 | /** |
||
222 | * Sets the client id |
||
223 | * @param string $id |
||
224 | * @codeCoverageIgnore |
||
225 | */ |
||
226 | public function setClientId($id) |
||
232 | |||
233 | /** |
||
234 | * Gets all tunnel clients |
||
235 | * @return TunnelClientCollection |
||
236 | */ |
||
237 | public function getTunnelClients() |
||
241 | |||
242 | /** |
||
243 | * Gets all tunnels |
||
244 | * @return TunnelCollection |
||
245 | */ |
||
246 | public function getTunnels() |
||
250 | |||
251 | /** |
||
252 | * Gets the dispatcher |
||
253 | * @return Dispatcher |
||
254 | */ |
||
255 | public function getDispatcher() |
||
259 | |||
260 | /** |
||
261 | * @return ConnectionInterface |
||
262 | */ |
||
263 | public function getControlConnection() |
||
267 | |||
268 | /** |
||
269 | * Sets a logger |
||
270 | * @param Logger $logger |
||
271 | */ |
||
272 | public function setLogger($logger) |
||
276 | |||
277 | /** |
||
278 | * Gets the logger |
||
279 | * @return Logger |
||
280 | */ |
||
281 | public function getLogger() |
||
285 | |||
286 | /** |
||
287 | * Gets the loop instance |
||
288 | * @return LoopInterface |
||
289 | */ |
||
290 | public function getLoop() |
||
294 | |||
295 | /** |
||
296 | * Creates a tunnel client to process proxy connection |
||
297 | * @param TunnelInterface $tunnel |
||
298 | * @param string $proxyConnectionId |
||
299 | * @return TunnelClientInterface |
||
300 | */ |
||
301 | public function createTunnelClient(TunnelInterface $tunnel, $proxyConnectionId) |
||
312 | |||
313 | /** |
||
314 | * Creates the handler for the received message |
||
315 | * @param SpikeInterface $message |
||
316 | * @param ConnectionInterface $connection |
||
317 | * @return Handler\HandlerInterface |
||
318 | * @codeCoverageIgnore |
||
319 | */ |
||
320 | protected function createMessageHandler(SpikeInterface $message, ConnectionInterface $connection) |
||
339 | |||
340 | /** |
||
341 | * Creates default timers |
||
342 | * @return TimerInterface[] |
||
343 | * @codeCoverageIgnore |
||
344 | */ |
||
345 | protected function getDefaultTimers() |
||
351 | } |