new Peer(host, port, network) → {Peer}
A Peer instance represents a remote bitcoin node and allows to communicate with it using the standar messages of the bitcoin p2p protocol.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
host |
String | IP address of the remote host |
|
port |
Number |
<optional> |
Port number of the remote host |
network |
Network |
<optional> |
The context for this communication |
- Source:
Returns:
A new instance of Peer.
- Type
- Peer
Example
var peer = new Peer('127.0.0.1').setProxy('127.0.0.1', 9050);
peer.on('tx', function(tx) {
console.log('New transaction: ', tx.id);
});
peer.connect();
Methods
-
_getSocket() → {Socket}
-
Internal function that creates a socket using a proxy if neccesary.
- Source:
Returns:
A Socket instance not yet connected.
- Type
- Socket
-
_readMessage()
-
Internal function that tries to read a message from the data buffer
- Source:
-
_sendPong()
-
Send a PONG message to the remote peer.
- Source:
-
_sendVersion()
-
Internal function that sends VERSION message to the remote peer.
- Source:
-
connect() → {Socket}
-
Init the connection with the remote peer.
- Source:
Returns:
The same peer instance.
- Type
- Socket
-
disconnect() → {Socket}
-
Disconnects the remote connection.
- Source:
Returns:
The same peer instance.
- Type
- Socket
-
sendMessage(message)
-
Send a Message to the remote peer.
Parameters:
Name Type Description messageMessage A message instance
- Source:
-
setProxy(host, port) → {Peer}
-
Set a socks5 proxy for the connection. Enables the use of the TOR network.
Parameters:
Name Type Description hostString IP address of the proxy
portNumber Port number of the proxy
- Source:
Returns:
The same Peer instance.
- Type
- Peer