1 | <?php |
||
11 | class Manager extends EventEmitter |
||
12 | { |
||
13 | /** |
||
14 | * @var Connector |
||
15 | */ |
||
16 | private $connector; |
||
17 | |||
18 | /** |
||
19 | * @var Peer[] |
||
20 | */ |
||
21 | private $outPeers = []; |
||
22 | |||
23 | /** |
||
24 | * @var Peer[] |
||
25 | */ |
||
26 | private $inPeers = []; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | private $nOutPeers = 0; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | private $nInPeers = 0; |
||
37 | |||
38 | /** |
||
39 | * Manager constructor. |
||
40 | * @param Connector $connector |
||
41 | */ |
||
42 | 6 | public function __construct(Connector $connector) |
|
46 | |||
47 | /** |
||
48 | * Store the newly connected peer, and trigger a new connection if they go away. |
||
49 | * |
||
50 | * @param Peer $peer |
||
51 | * @return Peer |
||
52 | */ |
||
53 | 2 | public function registerOutboundPeer(Peer $peer) |
|
65 | |||
66 | /** |
||
67 | * @param Peer $peer |
||
68 | */ |
||
69 | 3 | public function registerInboundPeer(Peer $peer) |
|
78 | |||
79 | /** |
||
80 | * @param Listener $listener |
||
81 | * @return $this |
||
82 | */ |
||
83 | 3 | public function registerListener(Listener $listener) |
|
91 | |||
92 | /** |
||
93 | * @param NetworkAddressInterface $address |
||
94 | * @return \React\Promise\PromiseInterface |
||
95 | * @throws \Exception |
||
96 | */ |
||
97 | 3 | public function connect(NetworkAddressInterface $address) |
|
101 | |||
102 | /** |
||
103 | * @param Locator $locator |
||
104 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
||
105 | */ |
||
106 | 3 | public function getAnotherPeer(Locator $locator) |
|
127 | |||
128 | /** |
||
129 | * @param Locator $locator |
||
130 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
||
131 | */ |
||
132 | 3 | public function attemptNextPeer(Locator $locator) { |
|
154 | |||
155 | /** |
||
156 | * @param Locator $locator |
||
157 | * @param int $retries |
||
158 | * @return \React\Promise\PromiseInterface |
||
159 | */ |
||
160 | public function connectNextPeer(Locator $locator, $retries = 5) |
||
187 | |||
188 | /** |
||
189 | * @param Locator $locator |
||
190 | * @param int $n |
||
191 | * @return \React\Promise\Promise |
||
192 | */ |
||
193 | 3 | public function connectToPeers(Locator $locator, $n) |
|
202 | } |
||
203 |