new Peer(pool, options, priority)
Represents a remote peer.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
pool |
Pool | ||||||||||
options |
Object |
Properties
|
|||||||||
priority |
Boolean | Whether this peer is high priority (i.e. a loader). |
|||||||||
options.chain |
Chain | ||||||||||
options.mempool |
Mempool | ||||||||||
options.bloom |
Bloom | The local bloom filter. |
|||||||||
options.ts |
Number |
<nullable> |
Time at which peer was discovered (unix time). |
||||||||
options.socket |
net.Socket |
<nullable> |
|||||||||
options.seed |
Seed |
<nullable> |
Host to connect to. |
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
pool |
Pool | ||
socket |
net.Socket |
<nullable> |
|
host |
String |
<nullable> |
|
port |
Number | ||
priority |
Boolean | ||
parser |
Parser | ||
framer |
Framer | ||
chain |
Chain | ||
mempool |
Mempool | ||
bloom |
Bloom | ||
version |
Object |
<nullable> |
Version packet payload. |
destroyed |
Boolean | ||
ack |
Boolean | Whether verack has been received. |
|
connected |
Boolean | ||
ts |
Number | ||
sendHeaders |
Boolean | Whether the peer has requested getheaders. |
|
haveWitness |
Boolean | Whether the peer supports segwit,
either notified via service bits or deprecated |
|
hashContinue |
Hash |
<nullable> |
The block hash at which to continue the sync for the peer. |
filter |
Bloom |
<nullable> |
The peer's bloom filter. |
relay |
Boolean | Whether to relay transactions immediately to the peer. |
|
challenge |
BN | Local nonce. |
|
lastPong |
Number | Timestamp for last |
|
id |
String | Peer's uid. |
|
banScore |
Number |
- Source:
Fires:
- Peer#event:ack
Methods
(private) _error(err)
Emit an error and destroy the peer.
Parameters:
Name | Type | Description |
---|---|---|
err |
String | Error |
- Source:
(private) _req(cmd, callback)
Wait for a packet to be received from peer.
Parameters:
Name | Type | Description |
---|---|---|
cmd |
String | Packet name. |
callback |
function | Returns [Error, Object(payload)]. Executed on timeout or once packet is received. |
- Source:
(private) _res(cmd, payload)
Fulfill awaiting requests created with Peer#_req.
Parameters:
Name | Type | Description |
---|---|---|
cmd |
String | Packet name. |
payload |
Object |
- Source:
broadcast(items) → {Array.<BroadcastPromise>}
Broadcast items to peer (transactions or blocks).
Parameters:
Name | Type | Description |
---|---|---|
items |
TX | Block | Array.<TX> | Array.<Block> |
- Source:
Returns:
- Type
- Array.<BroadcastPromise>
createSocket(host, port) → {net.Socket}
Create the socket and begin connecting. This method
will use options.createSocket
if provided.
Parameters:
Name | Type | Description |
---|---|---|
host |
String | |
port |
Number |
- Source:
Returns:
- Type
- net.Socket
destroy()
Disconnect from and destroy the peer.
- Source:
getBlocks(locator, stopnullable)
Send getblocks
to peer.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
locator |
Array.<Hash> | Chain locator. |
|
stop |
Hash |
<nullable> |
Hash to stop at. |
- Source:
getData(items)
Send getdata
to peer.
Parameters:
Name | Type | Description |
---|---|---|
items |
Array.<Object> | See Framer.getData. |
- Source:
getHeaders(locatornullable, stopnullable)
Send getheaders
to peer. Note that unlike
getblocks
, getheaders
can have a null locator.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
locator |
Array.<Hash> |
<nullable> |
Chain locator. |
stop |
Hash |
<nullable> |
Hash to stop at. |
- Source:
getMempool()
Send mempool
to peer.
- Source:
getUTXOs(utxos, callback)
Request UTXOs from peer.
Parameters:
Name | Type | Description |
---|---|---|
utxos |
Array.<Array> | Array in the form |
callback |
function | Returns [Error, Coin[]]. |
- Source:
isMisbehaving() → {Boolean}
Check whether the peer is misbehaving (banScore >= 100).
- Source:
Returns:
- Type
- Boolean
reject(details)
Send reject
to peer.
Parameters:
Name | Type | Description |
---|---|---|
details |
Object | See Framer.reject. |
- Source:
sendReject(objnullable, code, reason, score)
Send a reject
packet to peer.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
TX | Block |
<nullable> |
|
code |
String | cccode. |
|
reason |
String | ||
score |
Number |
- Source:
- See:
setMisbehavior(score)
Increase banscore on peer.
Parameters:
Name | Type | Description |
---|---|---|
score |
Number |
- Source:
updateWatch()
Send filterload
to update the local bloom filter.
- Source:
write(chunk) → {Boolean}
Write data to the peer's socket.
Parameters:
Name | Type | Description |
---|---|---|
chunk |
Buffer |
- Source:
Returns:
- Type
- Boolean