Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1ef06879e | ||
|
|
c44229feed | ||
|
|
e334370777 | ||
|
|
d1034b3a82 | ||
|
|
1b1ef05ada | ||
|
|
dae4c318c2 | ||
|
|
a062769cc4 | ||
|
|
f3cdb94450 | ||
|
|
25adf9f18f | ||
|
|
14f3c30ad3 | ||
|
|
335bd996b5 | ||
|
|
c898c3bc50 | ||
|
|
10a21524d8 | ||
|
|
c8e273aefe | ||
|
|
8d756c6c56 | ||
|
|
0e333f3248 | ||
|
|
d7970b2553 | ||
|
|
5de3ca9eab | ||
|
|
2fd4cbf622 | ||
|
|
f537eb86b9 | ||
|
|
59fbc03715 | ||
|
|
1ad1eed82a | ||
|
|
c41681d6c2 | ||
|
|
b7a6845a4f | ||
|
|
96c10c27ea | ||
|
|
e684688e4d | ||
|
|
8de9d91ee9 | ||
|
|
7bb9afd416 | ||
|
|
4d9f52ec98 | ||
|
|
55242db152 | ||
|
|
dbda30d4d1 | ||
|
|
0ea205d0eb | ||
|
|
6a88aaae9b | ||
|
|
1dfdd66b72 | ||
|
|
576ba8a2b6 | ||
|
|
5b2d3691cb | ||
|
|
c81875f014 | ||
|
|
d2eeb5e09e | ||
|
|
d951cbb3ba | ||
|
|
3a19287da1 | ||
|
|
d13da49c87 |
@ -1,6 +1,7 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '0.10'
|
||||
- '4'
|
||||
- '6'
|
||||
before_install:
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
|
||||
@ -1,18 +1,11 @@
|
||||
---
|
||||
title: Peer-to-Peer Networking
|
||||
description: Peer-to-Peer Networking Capabilities for Bitcore
|
||||
---
|
||||
# Peer-to-Peer
|
||||
|
||||
## Description
|
||||
|
||||
The `bitcore-p2p` module provides peer-to-peer networking capabilites for [Bitcore](https://github.com/bitpay/bitcore), and includes [Peer](peer.md) and [Pool](pool.md) classes. A [Message](messages.md) class is also exposed, in addition to [several types of messages](messages.md). Pool will maintain connection to several peers, Peers represents a node in the bitcoin network, and Message represents data sent to and from a Peer. For detailed technical information about the bitcoin protocol, please visit the [Protocol Specification](https://en.bitcoin.it/wiki/Protocol_specification) on the Bitcoin Wiki.
|
||||
The `bitcore-p2p` module provides peer-to-peer networking capabilities for [Bitcore](https://github.com/bitpay/bitcore), and includes [Peer](peer.md) and [Pool](pool.md) classes. A [Message](messages.md) class is also exposed, in addition to [several types of messages](messages.md). Pool will maintain connection to several peers, Peers represents a node in the bitcoin network, and Message represents data sent to and from a Peer. For detailed technical information about the bitcoin protocol, please visit the [Protocol Specification](https://en.bitcoin.it/wiki/Protocol_specification) on the Bitcoin Wiki.
|
||||
|
||||
## Installation
|
||||
|
||||
Peer-to-peer is implemented as a seperate module.
|
||||
Peer-to-peer is implemented as a separate module.
|
||||
|
||||
For node projects:
|
||||
|
||||
```bash
|
||||
npm install bitcore-p2p --save
|
||||
```
|
||||
@ -29,5 +22,4 @@ peer.on('inv', function(message) {
|
||||
});
|
||||
|
||||
peer.connect();
|
||||
|
||||
```
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
---
|
||||
title: Messages
|
||||
description: A superclass for the messages of the bitcoin network
|
||||
---
|
||||
# Messages
|
||||
|
||||
The bitcoin protocol specifies a set of [messages](https://en.bitcoin.it/wiki/Protocol_specification) that can be sent from peer to peer. `bitcore-p2p` provides support for some of these messages.
|
||||
|
||||
To create a message, you can use any of the message constructors, here is a simple example:
|
||||
@ -43,21 +38,16 @@ var messages = new Messages({network: Networks.testnet});
|
||||
```
|
||||
|
||||
## List of Messages
|
||||
|
||||
### Version
|
||||
|
||||
The version message (`ver`) is used on connection creation, to advertise the type of node. The remote node will respond with its version, and no communication is possible until both peers have exchanged their versions. By default, bitcore advertises itself as named `bitcore` with the current version of the `bitcore-p2p` package.
|
||||
|
||||
### VerAck
|
||||
|
||||
Finishes the connection handshake started by the `ver` message.
|
||||
|
||||
### Inventory
|
||||
|
||||
From the bitcoin protocol spec: "Allows a node to advertise its knowledge of one or more objects. It can be received unsolicited, or in reply to getblocks.".
|
||||
|
||||
### GetData
|
||||
|
||||
From the bitcoin protocol spec: `getdata` is used in response to `inv`, to retrieve the content of a specific object, and is usually sent after receiving an `inv` packet, after filtering known elements. It can be used to retrieve transactions, but only if they are in the memory pool or relay set - arbitrary access to transactions in the chain is not allowed to avoid having clients start to depend on nodes having full transaction indexes (which modern nodes do not).
|
||||
|
||||
GetData inherits from Inventory, as they both have the same structure.
|
||||
@ -66,31 +56,24 @@ GetData inherits from Inventory, as they both have the same structure.
|
||||
notfound is a response to a getdata, sent if any requested data items could not be relayed, for example, because the requested transaction was not in the memory pool or relay set. Contains inventory information specifying which items were not found.
|
||||
|
||||
### Ping
|
||||
|
||||
Sent to another peer mainly to check the connection is still alive.
|
||||
|
||||
### Pong
|
||||
|
||||
Sent in response to a `ping` message.
|
||||
|
||||
### Address and GetAddresses
|
||||
|
||||
Provides information on known nodes of the network. `GetAddresses` is used to query another peer for known addresses.
|
||||
|
||||
### GetHeaders and Headers
|
||||
|
||||
`getheaders` allows a peer to query another about blockheaders. `headers` is sent in response to a `getheaders` message, containing information about block headers.
|
||||
|
||||
### GetBlocks and Block
|
||||
|
||||
Same as `getheaders` and `headers`, but the response comes one block at the time.
|
||||
|
||||
### Transaction
|
||||
|
||||
Message that contains a transaction.
|
||||
|
||||
## Custom Messages
|
||||
|
||||
It is possible to extend the default peer to peer messages and add custom ones. First you will need to create a message which resembles the default messages in `lib/messages/commands`.
|
||||
|
||||
Then to add the custom message:
|
||||
|
||||
20
docs/peer.md
20
docs/peer.md
@ -1,15 +1,7 @@
|
||||
---
|
||||
title: Peer
|
||||
description: The Peer class provides a simple interface for connecting to a node in the bitcoin network.
|
||||
---
|
||||
# Peer
|
||||
|
||||
## Description
|
||||
|
||||
Represents a node from the p2p bitcoin network. The Peer class supports connecting directly to other nodes or through a socks5 proxy like Tor.
|
||||
|
||||
## Creating a peer
|
||||
|
||||
The code to create a new peer looks like this:
|
||||
|
||||
```javascript
|
||||
@ -28,13 +20,11 @@ var peer = new Peer({host: '5.9.85.34'}).setProxy('localhost', 9050);
|
||||
```
|
||||
|
||||
## States
|
||||
|
||||
A peer instance is always in one of the following states:
|
||||
|
||||
* `disconnected`: No connection with the remote node.
|
||||
* `connecting`: While establishing the connection.
|
||||
* `connected`: Exchanging version packages.
|
||||
* `ready`: Connection ready for sending and receiving messages.
|
||||
- `disconnected`: No connection with the remote node.
|
||||
- `connecting`: While establishing the connection.
|
||||
- `connected`: Exchanging version packages.
|
||||
- `ready`: Connection ready for sending and receiving messages.
|
||||
|
||||
You can subscribe to the change of those states as follows:
|
||||
|
||||
@ -56,7 +46,6 @@ peer.connect();
|
||||
```
|
||||
|
||||
## Handle messages
|
||||
|
||||
Once connected, a peer instance can send and receive messages. Every time a message arrives it's emitted as a new event. Let's see an example of this:
|
||||
|
||||
```javascript
|
||||
@ -80,7 +69,6 @@ peer.connect();
|
||||
```
|
||||
|
||||
## Sending messages
|
||||
|
||||
In order to send messages the Peer class offers the `sendMessage(message)` method, which receives an instance of a message. All supported messages can be found in the `Messages` module. For more information about messages refer to the [protocol specification](https://en.bitcoin.it/wiki/Protocol_specification).
|
||||
|
||||
An example for requesting other connected nodes to a peers looks like this:
|
||||
|
||||
11
docs/pool.md
11
docs/pool.md
@ -1,9 +1,4 @@
|
||||
---
|
||||
title: Pool
|
||||
description: A simple interface to create and maintain a set of connections to bitcoin nodes.
|
||||
---
|
||||
# Pool
|
||||
|
||||
A pool maintains a connection of [Peers](peer.md). A pool will discover peers via DNS seeds, as well as when peer addresses are announced through the network.
|
||||
|
||||
The quickest way to get connected is to run the following:
|
||||
@ -25,13 +20,11 @@ pool.on('peerinv', function(peer, message) {
|
||||
|
||||
// will disconnect all peers
|
||||
pool.disconnect()
|
||||
|
||||
```
|
||||
|
||||
For more information about Peer events please read the [Peer](peer.md) documentation. Peer events are relayed to the pool, a peer event `inv` in the pool would be `peerinv`. When a peer is disconnected the pool will try to connect to the list of known addresses to maintain connection.
|
||||
|
||||
## Trusted Peers
|
||||
|
||||
By default, peers will be added via DNS discovery and as peers are announced in the network. Configuration options can be included to connect only to specific trusted peers:
|
||||
|
||||
```javascript
|
||||
@ -50,11 +43,9 @@ var pool = new Pool({
|
||||
});
|
||||
|
||||
pool.connect();
|
||||
|
||||
```
|
||||
|
||||
## Listening for Peers
|
||||
|
||||
It's also possible to listen to incoming socket connections to add peers to the pool. To enable this capability, you can do the following:
|
||||
|
||||
```javascript
|
||||
@ -62,4 +53,4 @@ var pool = new Pool({network: Networks.livenet});
|
||||
pool.listen();
|
||||
```
|
||||
|
||||
When there are incoming connections the peer will be added to the pool.
|
||||
When there are incoming connections the peer will be added to the pool.
|
||||
|
||||
2
index.js
2
index.js
@ -1,4 +1,4 @@
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
bitcore.P2P = require('./lib');
|
||||
|
||||
module.exports = bitcore.P2P;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BloomFilter = require('bloom-filter');
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -5,4 +5,4 @@ var spec = {
|
||||
message: 'Internal Error on bitcore-p2p Module {0}'
|
||||
};
|
||||
|
||||
module.exports = require('bitcore-lib').errors.extend(spec);
|
||||
module.exports = require('flocore-lib').errors.extend(spec);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var fcoin = require('fcoin');
|
||||
var Inventory = require('../inventory');
|
||||
|
||||
function builder(options) {
|
||||
@ -15,11 +16,11 @@ function builder(options) {
|
||||
options.network = bitcore.Networks.defaultNetwork;
|
||||
}
|
||||
|
||||
options.Block = options.Block || bitcore.Block;
|
||||
options.Block = options.Block || fcoin.Block;
|
||||
options.BlockHeader = options.BlockHeader || bitcore.BlockHeader;
|
||||
options.Transaction = options.Transaction || bitcore.Transaction;
|
||||
options.Transaction = options.Transaction || fcoin.TX;
|
||||
options.MerkleBlock = options.MerkleBlock || bitcore.MerkleBlock;
|
||||
options.protocolVersion = options.protocolVersion || 70000;
|
||||
options.protocolVersion = options.protocolVersion || 70001;
|
||||
|
||||
var exported = {
|
||||
constructors: {
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
|
||||
@ -26,10 +26,17 @@ function BlockMessage(arg, options) {
|
||||
inherits(BlockMessage, Message);
|
||||
|
||||
BlockMessage.prototype.setPayload = function(payload) {
|
||||
this.block = this.Block.fromBuffer(payload);
|
||||
if (typeof this.Block.fromRaw === 'function') {
|
||||
this.block = this.Block.fromRaw(payload);
|
||||
} else {
|
||||
this.block = this.Block.fromBuffer(payload);
|
||||
}
|
||||
};
|
||||
|
||||
BlockMessage.prototype.getPayload = function() {
|
||||
if (typeof this.Block.fromRaw === 'function') {
|
||||
return this.block.toRaw();
|
||||
}
|
||||
return this.block.toBuffer();
|
||||
};
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
|
||||
/**
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
var BloomFilter = require('../../bloomfilter');
|
||||
var $ = bitcore.util.preconditions;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
|
||||
/**
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
|
||||
/**
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
|
||||
@ -2,20 +2,66 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
var bitcore = require('flocore-lib');
|
||||
var utils = require('../utils');
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
// todo: add payload: https://en.bitcoin.it/wiki/Protocol_documentation#reject
|
||||
/**
|
||||
* The reject message is sent when messages are rejected.
|
||||
*
|
||||
* @see https://en.bitcoin.it/wiki/Protocol_documentation#reject
|
||||
* @param {Object=} arg - properties for the reject message
|
||||
* @param {String=} arg.message - type of message rejected
|
||||
* @param {Number=} arg.ccode - code relating to rejected message
|
||||
* @param {String=} arg.reason - text version of reason for rejection
|
||||
* @param {Buffer=} arg.data - Optional extra data provided by some errors.
|
||||
* @param {Object} options
|
||||
* @extends Message
|
||||
* @constructor
|
||||
*/
|
||||
function RejectMessage(arg, options) {
|
||||
if (!arg) {
|
||||
arg = {};
|
||||
}
|
||||
Message.call(this, options);
|
||||
this.command = 'reject';
|
||||
this.message = arg.message;
|
||||
this.ccode = arg.ccode;
|
||||
this.reason = arg.reason;
|
||||
this.data = arg.data;
|
||||
}
|
||||
inherits(RejectMessage, Message);
|
||||
|
||||
RejectMessage.prototype.setPayload = function() {};
|
||||
RejectMessage.CCODE = {
|
||||
REJECT_MALFORMED: 0x01,
|
||||
REJECT_INVALID: 0x10,
|
||||
REJECT_OBSOLETE: 0x11,
|
||||
REJECT_DUPLICATE: 0x12,
|
||||
REJECT_NONSTANDARD: 0x40,
|
||||
REJECT_DUST: 0x41,
|
||||
REJECT_INSUFFICIENTFEE: 0x42,
|
||||
REJECT_CHECKPOINT: 0x43
|
||||
};
|
||||
|
||||
RejectMessage.prototype.setPayload = function(payload) {
|
||||
var parser = new BufferReader(payload);
|
||||
this.message = parser.readVarLengthBuffer().toString('utf-8');
|
||||
this.ccode = parser.readUInt8();
|
||||
this.reason = parser.readVarLengthBuffer().toString('utf-8');
|
||||
this.data = parser.readAll();
|
||||
utils.checkFinished(parser);
|
||||
};
|
||||
|
||||
RejectMessage.prototype.getPayload = function() {
|
||||
return BufferUtil.EMPTY_BUFFER;
|
||||
var bw = new BufferWriter();
|
||||
bw.writeVarintNum(this.message.length);
|
||||
bw.write(new Buffer(this.message, 'utf-8'));
|
||||
bw.writeUInt8(this.ccode);
|
||||
bw.writeVarintNum(this.reason.length);
|
||||
bw.write(new Buffer(this.reason, 'utf-8'));
|
||||
bw.write(this.data);
|
||||
return bw.toBuffer();
|
||||
};
|
||||
|
||||
module.exports = RejectMessage;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
|
||||
@ -28,7 +28,9 @@ function TransactionMessage(arg, options) {
|
||||
inherits(TransactionMessage, Message);
|
||||
|
||||
TransactionMessage.prototype.setPayload = function(payload) {
|
||||
if (this.Transaction.prototype.fromBuffer) {
|
||||
if (typeof this.Transaction.fromRaw === 'function') {
|
||||
this.transaction = this.Transaction.fromRaw(payload);
|
||||
} else if (this.Transaction.prototype.fromBuffer) {
|
||||
this.transaction = new this.Transaction().fromBuffer(payload);
|
||||
} else {
|
||||
this.transaction = this.Transaction.fromBuffer(payload);
|
||||
@ -36,6 +38,9 @@ TransactionMessage.prototype.setPayload = function(payload) {
|
||||
};
|
||||
|
||||
TransactionMessage.prototype.getPayload = function() {
|
||||
if (typeof this.Transaction.fromRaw === 'function') {
|
||||
return this.transaction.toRaw();
|
||||
}
|
||||
return this.transaction.toBuffer();
|
||||
};
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
|
||||
/**
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BN = bitcore.crypto.BN;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
var Hash = bitcore.crypto.Hash;
|
||||
var $ = bitcore.util.preconditions;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
var Hash = bitcore.crypto.Hash;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
|
||||
@ -4,7 +4,8 @@ var Buffers = require('./buffers');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Net = require('net');
|
||||
var Socks5Client = require('socks5-client');
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var bcoin = require('fcoin');
|
||||
var Networks = bitcore.Networks;
|
||||
var Messages = require('./messages');
|
||||
var $ = bitcore.util.preconditions;
|
||||
@ -65,8 +66,8 @@ function Peer(options) {
|
||||
|
||||
this.messages = options.messages || new Messages({
|
||||
network: this.network,
|
||||
Block: bitcore.Block,
|
||||
Transaction: bitcore.Transaction
|
||||
Block: bcoin.block,
|
||||
Transaction: bcoin.tx
|
||||
});
|
||||
|
||||
this.dataBuffer = new Buffers();
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
var dns = require('dns');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var bitcore = require('bitcore-lib');
|
||||
var bitcore = require('flocore-lib');
|
||||
var sha256 = bitcore.crypto.Hash.sha256;
|
||||
var Peer = require('./peer');
|
||||
var Networks = bitcore.Networks;
|
||||
@ -116,7 +116,7 @@ Pool.PeerEvents = ['version', 'inv', 'getdata', 'ping', 'pong', 'addr',
|
||||
];
|
||||
|
||||
/**
|
||||
* Will initiatiate connection to peers, if available peers have been added to
|
||||
* Will initiate connection to peers, if available peers have been added to
|
||||
* the pool, it will connect to those, otherwise will use DNS seeds to find
|
||||
* peers to connect. When a peer disconnects it will add another.
|
||||
*/
|
||||
@ -150,7 +150,7 @@ Pool.prototype.numberConnected = function numberConnected() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Will fill the conneted peers to the maximum amount.
|
||||
* Will fill the connected peers to the maximum amount.
|
||||
*/
|
||||
Pool.prototype._fillConnections = function _fillConnections() {
|
||||
var length = this._addrs.length;
|
||||
@ -211,7 +211,7 @@ Pool.prototype._connectPeer = function _connectPeer(addr) {
|
||||
|
||||
/**
|
||||
* Adds a peer with a connected socket to the _connectedPeers object, and
|
||||
* intializes the associated event handlers.
|
||||
* initializes the associated event handlers.
|
||||
* @param {Socket} - socket - A new connected socket
|
||||
* @param {Object} - addr - The associated addr object for the peer
|
||||
*/
|
||||
|
||||
2446
package-lock.json
generated
Normal file
2446
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@ -1,8 +1,7 @@
|
||||
{
|
||||
"name": "bitcore-p2p",
|
||||
"version": "0.15.1",
|
||||
"description": "Interface to the bitcoin P2P network for bitcore",
|
||||
"author": "BitPay <dev@bitpay.com>",
|
||||
"name": "flocore-p2p",
|
||||
"version": "5.0.0-beta.8",
|
||||
"description": "Interface to the Flo P2P network for flocore",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "gulp lint",
|
||||
@ -10,39 +9,6 @@
|
||||
"coverage": "gulp coverage",
|
||||
"build": "gulp"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Yemel Jardi",
|
||||
"email": "yemel@bitpay.com"
|
||||
},
|
||||
{
|
||||
"name": "Braydon Fuller",
|
||||
"email": "braydon@bitpay.com"
|
||||
},
|
||||
{
|
||||
"name": "Ryan X. Charles",
|
||||
"email": "ryan@bitpay.com"
|
||||
},
|
||||
{
|
||||
"name": "Eric Martindale",
|
||||
"email": "eric@bitpay.com"
|
||||
},
|
||||
{
|
||||
"name": "Philip Hutchins",
|
||||
"email": "philip@bitpay.com"
|
||||
},
|
||||
{
|
||||
"name": "Manuel Araoz",
|
||||
"email": "maraoz@bitpay.com"
|
||||
},
|
||||
{
|
||||
"name": "Esteban Ordano",
|
||||
"email": "eordano@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Elichai Turkel"
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"bitcoin",
|
||||
"bitcore"
|
||||
@ -52,9 +18,10 @@
|
||||
"url": "https://github.com/bitpay/bitcore-p2p.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"bitcore-lib": "^0.13.7",
|
||||
"bloom-filter": "^0.2.0",
|
||||
"buffers": "^0.1.1",
|
||||
"buffers": "bitpay/node-buffers#v0.1.2-bitpay",
|
||||
"fcoin": "^1.1.0",
|
||||
"flocore-lib": "^0.15.2",
|
||||
"socks5-client": "^0.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
"message": "f9beb4d9616c65727400000000000000bc0000004fe68fe973010000003766404f00000000b305434f00000000f2030000f1030000001027000048ee00000064000000004653656520626974636f696e2e6f72672f666562323020696620796f7520686176652074726f75626c6520636f6e6e656374696e67206166746572203230204665627275617279004730450221008389df45f0703f39ec8c1cc42c13810ffcae14995bb648340219e353b63b53eb022009ec65e1c1aaeec1fd334c6b684bde2b3f573060d5b70c3a46723326e4e8a4f1"
|
||||
},
|
||||
"reject": {
|
||||
"message": "f9beb4d972656a656374000000000000000000005df6e0e2"
|
||||
"message": "f9beb4d972656a6563740000000000003a000000f44033160274780015696e73756666696369656e74207072696f72697479165d408c9dd26fbdcb42b07546f6c37752301e3772f3ae441baf569e78839111"
|
||||
},
|
||||
"notfound": {
|
||||
"message": "f9beb4d96e6f74666f756e6400000000250000001d33d53201010000003a4af715be220eae7b2657582869daddf79ac4afb4a0e1cafa5b57e1afb8dfe2"
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var should = require('chai').should();
|
||||
var expect = require('chai').expect;
|
||||
var P2P = require('../../../');
|
||||
var Messages = P2P.Messages;
|
||||
var sinon = require('sinon');
|
||||
@ -263,6 +264,43 @@ describe('Command Messages', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Reject', function() {
|
||||
it('should set properties from arg in constructor', function() {
|
||||
var message = messages.Reject({
|
||||
message: 'tx',
|
||||
ccode: 0x01,
|
||||
reason: 'transaction is malformed',
|
||||
data: new Buffer('12345678901234567890123456789012', 'hex')
|
||||
});
|
||||
message.message.should.equal('tx');
|
||||
message.ccode.should.equal(0x01);
|
||||
message.reason.should.equal('transaction is malformed');
|
||||
message.data.toString('hex').should.equal('12345678901234567890123456789012');
|
||||
});
|
||||
it('should let arg be optional in constructor', function() {
|
||||
var message = messages.Reject();
|
||||
expect(message.message).to.be.undefined;
|
||||
expect(message.ccode).to.be.undefined;
|
||||
expect(message.reason).to.be.undefined;
|
||||
expect(message.data).to.be.undefined;
|
||||
});
|
||||
it('should write payload correctly', function() {
|
||||
var message = messages.Reject({
|
||||
message: 'tx',
|
||||
ccode: 0x01,
|
||||
reason: 'transaction is malformed',
|
||||
data: new Buffer('12345678901234567890123456789012', 'hex')
|
||||
});
|
||||
var payload = message.getPayload();
|
||||
message = messages.Reject();
|
||||
message.setPayload(payload);
|
||||
message.message.should.equal('tx');
|
||||
message.ccode.should.equal(0x01);
|
||||
message.reason.should.equal('transaction is malformed');
|
||||
message.data.toString('hex').should.equal('12345678901234567890123456789012');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Version', function() {
|
||||
it('should set the default relay property as true', function() {
|
||||
var message = messages.Version();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user