1 | <?php |
||
13 | class Factory |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var NetworkInterface |
||
18 | */ |
||
19 | private $network; |
||
20 | |||
21 | /** |
||
22 | * @var LoopInterface |
||
23 | */ |
||
24 | private $loop; |
||
25 | |||
26 | /** |
||
27 | * @param NetworkInterface $network |
||
28 | * @param LoopInterface $loop |
||
29 | */ |
||
30 | 18 | public function __construct(LoopInterface $loop, NetworkInterface $network = null) |
|
31 | { |
||
32 | 18 | $this->loop = $loop; |
|
33 | 18 | $this->network = $network ?: Bitcoin::getNetwork(); |
|
34 | 18 | } |
|
35 | |||
36 | /** |
||
37 | * @param string $host |
||
38 | * @return Dns\Resolver |
||
39 | */ |
||
40 | 18 | public function getDns($host = '8.8.8.8') |
|
41 | { |
||
42 | 18 | return (new Dns\Factory())->create($host, $this->loop); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param Random|null $random |
||
47 | * @return Messages\Factory |
||
48 | */ |
||
49 | 12 | public function getMessages(Random $random = null) |
|
50 | { |
||
51 | 12 | return new Messages\Factory( |
|
52 | 12 | $this->network, |
|
53 | 12 | $random ?: new Random() |
|
54 | 12 | ); |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param string $ipAddress |
||
59 | * @param int $port |
||
60 | * @param BufferInterface|null $services |
||
61 | * @return NetworkAddress |
||
62 | */ |
||
63 | 6 | public function getAddress($ipAddress, $port = 8333, BufferInterface $services = null) |
|
71 | } |
||
72 |