1 | <?php |
||
14 | class Locator |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @var Resolver |
||
19 | */ |
||
20 | private $dns; |
||
21 | |||
22 | /** |
||
23 | * @var DnsSeedList |
||
24 | */ |
||
25 | private $seeds; |
||
26 | |||
27 | /** |
||
28 | * @var NetworkAddressInterface[] |
||
29 | */ |
||
30 | private $knownAddresses = []; |
||
31 | |||
32 | /** |
||
33 | * Locator constructor. |
||
34 | * @param Resolver $dns |
||
35 | * @param NetworkSettings $settings |
||
36 | */ |
||
37 | 12 | public function __construct(Resolver $dns, NetworkSettings $settings) |
|
43 | |||
44 | /** |
||
45 | * Takes an arbitrary list of dns seed hostnames, and attempts |
||
46 | * to return a list from each. Request fails if any hosts are |
||
47 | * offline or cause an error. |
||
48 | * |
||
49 | * @param array $seeds |
||
50 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
||
51 | */ |
||
52 | 9 | public function querySeeds(array $seeds) |
|
74 | |||
75 | /** |
||
76 | * Given a number of DNS seeds to query, select a random few and |
||
77 | * return their peers. |
||
78 | * |
||
79 | * @param int $numSeeds |
||
80 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
||
81 | */ |
||
82 | 6 | private function getPeerList($numSeeds = 1) |
|
91 | |||
92 | /** |
||
93 | * Query $numSeeds DNS seeds, returning the NetworkAddress[] result. |
||
94 | * Is rejected if any of the seeds fail. |
||
95 | * |
||
96 | * @param int $numSeeds |
||
97 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
||
98 | */ |
||
99 | 6 | public function queryDnsSeeds($numSeeds = 1) |
|
133 | |||
134 | /** |
||
135 | * @return NetworkAddressInterface[] |
||
136 | */ |
||
137 | 3 | public function getKnownAddresses() |
|
141 | |||
142 | /** |
||
143 | * Pop an address from the discovered peers |
||
144 | * |
||
145 | * @return NetworkAddressInterface |
||
146 | * @throws \Exception |
||
147 | */ |
||
148 | 6 | public function popAddress() |
|
156 | } |
||
157 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: