1 | <?php |
||
29 | class Peer extends EventEmitter |
||
30 | { |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $buffer = ''; |
||
35 | |||
36 | /** |
||
37 | * @var LoopInterface |
||
38 | */ |
||
39 | private $loop; |
||
40 | |||
41 | /** |
||
42 | * @var \BitWasp\Bitcoin\Networking\Messages\Factory |
||
43 | */ |
||
44 | private $msgs; |
||
45 | |||
46 | /** |
||
47 | * @var Stream |
||
48 | */ |
||
49 | private $stream; |
||
50 | |||
51 | /** |
||
52 | * @var Version |
||
53 | */ |
||
54 | private $localVersion; |
||
55 | |||
56 | /** |
||
57 | * @var Version |
||
58 | */ |
||
59 | private $remoteVersion; |
||
60 | |||
61 | /** |
||
62 | * @var NetworkAddressInterface |
||
63 | */ |
||
64 | private $peerAddress; |
||
65 | |||
66 | /** |
||
67 | * @var ConnectionParams |
||
68 | */ |
||
69 | private $connectionParams; |
||
70 | |||
71 | /** |
||
72 | * @var bool |
||
73 | */ |
||
74 | private $exchangedVersion = false; |
||
75 | |||
76 | /** |
||
77 | * @param \BitWasp\Bitcoin\Networking\Messages\Factory $msgs |
||
78 | * @param LoopInterface $loop |
||
79 | */ |
||
80 | 12 | public function __construct(\BitWasp\Bitcoin\Networking\Messages\Factory $msgs, LoopInterface $loop) |
|
85 | |||
86 | /** |
||
87 | * @return Version |
||
88 | */ |
||
89 | 3 | public function getLocalVersion() |
|
90 | { |
||
91 | 3 | return $this->localVersion; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return Version |
||
96 | */ |
||
97 | 3 | public function getRemoteVersion() |
|
98 | { |
||
99 | 3 | return $this->remoteVersion; |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * Reliably returns the remote peers NetAddr when known through |
||
104 | * the connection process. Often better than the data contained |
||
105 | * in a Version message. |
||
106 | * |
||
107 | * @return NetworkAddressInterface |
||
108 | */ |
||
109 | 3 | public function getRemoteAddress() |
|
110 | { |
||
111 | 3 | return $this->peerAddress; |
|
112 | } |
||
113 | |||
114 | /** |
||
115 | * @return ConnectionParams |
||
116 | */ |
||
117 | 3 | public function getConnectionParams() |
|
118 | { |
||
119 | 3 | return $this->connectionParams; |
|
120 | } |
||
121 | |||
122 | /** |
||
123 | * @param NetworkSerializable $msg |
||
124 | */ |
||
125 | 12 | public function send(NetworkSerializable $msg) |
|
131 | |||
132 | /** |
||
133 | * Handler for incoming data. Buffers possibly fragmented packets since they arrive sequentially. |
||
134 | * Before finishing the version exchange, this will only emit Version and VerAck messages. |
||
135 | */ |
||
136 | 12 | private function onData() |
|
151 | |||
152 | /** |
||
153 | * @param Stream $stream |
||
154 | * @return $this |
||
155 | */ |
||
156 | 12 | public function setupStream(Stream $stream) |
|
178 | |||
179 | /** |
||
180 | * @param Stream $connection |
||
181 | * @param ConnectionParams $params |
||
182 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
||
183 | */ |
||
184 | 9 | public function inboundHandshake(Stream $connection, ConnectionParams $params) |
|
210 | |||
211 | /** |
||
212 | * @param NetworkAddressInterface $remotePeer |
||
213 | * @param ConnectionParams $params |
||
214 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
||
215 | */ |
||
216 | 12 | public function outboundHandshake(NetworkAddressInterface $remotePeer, ConnectionParams $params) |
|
241 | |||
242 | /** |
||
243 | * |
||
244 | */ |
||
245 | public function intentionalClose() |
||
250 | |||
251 | /** |
||
252 | * |
||
253 | */ |
||
254 | 9 | public function close() |
|
260 | |||
261 | /** |
||
262 | * @param int $protocolVersion |
||
263 | * @param int $services |
||
264 | * @param int $timestamp |
||
265 | * @param NetworkAddressInterface $remoteAddr |
||
266 | * @param NetworkAddressInterface $localAddr |
||
267 | * @param string $userAgent |
||
268 | * @param int $blockHeight |
||
269 | * @param bool $relayToUs |
||
270 | */ |
||
271 | public function version( |
||
292 | |||
293 | /** |
||
294 | * |
||
295 | */ |
||
296 | 12 | public function verack() |
|
300 | |||
301 | /** |
||
302 | * |
||
303 | */ |
||
304 | public function sendheaders() |
||
308 | |||
309 | /** |
||
310 | * @param Inventory[] $vInv |
||
311 | */ |
||
312 | public function inv(array $vInv) |
||
316 | |||
317 | /** |
||
318 | * @param Inventory[] $vInv |
||
319 | */ |
||
320 | public function getdata(array $vInv) |
||
324 | |||
325 | /** |
||
326 | * @param array $vInv |
||
327 | */ |
||
328 | public function notfound(array $vInv) |
||
332 | |||
333 | /** |
||
334 | * @param NetworkAddressTimestamp[] $vNetAddr |
||
335 | */ |
||
336 | public function addr(array $vNetAddr) |
||
340 | |||
341 | /** |
||
342 | * |
||
343 | */ |
||
344 | public function getaddr() |
||
348 | |||
349 | /** |
||
350 | * |
||
351 | */ |
||
352 | public function ping() |
||
356 | |||
357 | /** |
||
358 | * @param Ping $ping |
||
359 | */ |
||
360 | public function pong(Ping $ping) |
||
364 | |||
365 | /** |
||
366 | * @param TransactionInterface $tx |
||
367 | */ |
||
368 | public function tx(TransactionInterface $tx) |
||
372 | |||
373 | /** |
||
374 | * @param BlockLocator $locator |
||
375 | */ |
||
376 | public function getblocks(BlockLocator $locator) |
||
383 | |||
384 | /** |
||
385 | * @param BlockLocator $locator |
||
386 | */ |
||
387 | public function getheaders(BlockLocator $locator) |
||
394 | |||
395 | /** |
||
396 | * @param BlockInterface $block |
||
397 | */ |
||
398 | public function block(BlockInterface $block) |
||
402 | |||
403 | /** |
||
404 | * @param array $vHeaders |
||
405 | */ |
||
406 | public function headers(array $vHeaders) |
||
410 | |||
411 | /** |
||
412 | * @param AlertDetail $detail |
||
413 | * @param SignatureInterface $signature |
||
414 | */ |
||
415 | public function alert(AlertDetail $detail, SignatureInterface $signature) |
||
419 | |||
420 | /** |
||
421 | * @param int $feeRate |
||
422 | */ |
||
423 | public function feefilter($feeRate) |
||
427 | |||
428 | /** |
||
429 | * @param BufferInterface $data |
||
430 | */ |
||
431 | public function filteradd(BufferInterface $data) |
||
435 | |||
436 | /** |
||
437 | * @param BloomFilter $filter |
||
438 | */ |
||
439 | public function filterload(BloomFilter $filter) |
||
443 | |||
444 | /** |
||
445 | * |
||
446 | */ |
||
447 | public function filterclear() |
||
451 | |||
452 | /** |
||
453 | * @param FilteredBlock $filtered |
||
454 | */ |
||
455 | public function merkleblock(FilteredBlock $filtered) |
||
459 | |||
460 | /** |
||
461 | * |
||
462 | */ |
||
463 | public function mempool() |
||
467 | |||
468 | /** |
||
469 | * Issue a Reject message, with a required $msg, $code, and $reason |
||
470 | * |
||
471 | * @param BufferInterface $msg |
||
472 | * @param int $code |
||
473 | * @param BufferInterface $reason |
||
474 | * @param BufferInterface $data |
||
475 | */ |
||
476 | public function reject(BufferInterface $msg, $code, BufferInterface $reason, BufferInterface $data = null) |
||
480 | } |
||
481 |