1 | <?php |
||
14 | class Factory |
||
15 | { |
||
16 | /** |
||
17 | * @var Resolver |
||
18 | */ |
||
19 | private $dns; |
||
20 | |||
21 | /** |
||
22 | * @var NetworkAddressInterface |
||
23 | */ |
||
24 | private $local; |
||
25 | |||
26 | /** |
||
27 | * @var LoopInterface |
||
28 | */ |
||
29 | private $loop; |
||
30 | |||
31 | /** |
||
32 | * @var \BitWasp\Bitcoin\Networking\Messages\Factory |
||
33 | */ |
||
34 | private $msgFactory; |
||
35 | |||
36 | /** |
||
37 | * @param Resolver $dns |
||
38 | * @param \BitWasp\Bitcoin\Networking\Messages\Factory $factory |
||
39 | * @param LoopInterface $loop |
||
40 | * @param NetworkAddressInterface $localAddress |
||
41 | */ |
||
42 | public function __construct( |
||
43 | 24 | Resolver $dns, |
|
44 | \BitWasp\Bitcoin\Networking\Messages\Factory $factory, |
||
45 | LoopInterface $loop, |
||
46 | NetworkAddressInterface $localAddress = null |
||
47 | ) { |
||
48 | $this->dns = $dns; |
||
49 | 24 | $this->msgFactory = $factory; |
|
50 | 24 | $this->loop = $loop; |
|
51 | 24 | $this->setLocalAddr($localAddress ?: $this->getAddress('0.0.0.0')); |
|
52 | 24 | } |
|
53 | 24 | ||
54 | /** |
||
55 | * @return Connector |
||
56 | */ |
||
57 | public function getConnector() |
||
61 | |||
62 | /** |
||
63 | * @return Server |
||
64 | */ |
||
65 | public function getServer() |
||
69 | |||
70 | /** |
||
71 | * @param NetworkAddressInterface $localAddress |
||
72 | */ |
||
73 | public function setLocalAddr(NetworkAddressInterface $localAddress) |
||
74 | 24 | { |
|
75 | $this->local = $localAddress; |
||
76 | 24 | } |
|
77 | 24 | ||
78 | /** |
||
79 | * @param string $ipAddress |
||
80 | * @param int $port |
||
81 | * @param BufferInterface|null $services |
||
82 | * @return NetworkAddress |
||
83 | */ |
||
84 | public function getAddress($ipAddress, $port = 8333, BufferInterface $services = null) |
||
85 | 24 | { |
|
86 | return new NetworkAddress( |
||
87 | 24 | $services ?: Buffer::hex('0000000000000001'), |
|
88 | 24 | $ipAddress, |
|
89 | 24 | $port |
|
90 | ); |
||
91 | 24 | } |
|
92 | |||
93 | /** |
||
94 | * @return Peer |
||
95 | */ |
||
96 | public function getPeer() |
||
97 | 15 | { |
|
98 | return new Peer( |
||
99 | 15 | $this->local, |
|
100 | 15 | $this->msgFactory, |
|
101 | 15 | $this->loop |
|
102 | 15 | ); |
|
103 | 15 | } |
|
104 | |||
105 | /** |
||
106 | * @return Locator |
||
107 | */ |
||
108 | public function getLocator() |
||
112 | |||
113 | /** |
||
114 | * @param bool|false $shouldRelay |
||
115 | * @return Manager |
||
116 | */ |
||
117 | 3 | public function getManager($shouldRelay = false) |
|
121 | |||
122 | /** |
||
123 | * @param Server $server |
||
124 | * @return Listener |
||
125 | */ |
||
126 | 12 | public function getListener(Server $server) |
|
130 | } |
||
131 |