Compare commits

...

41 Commits

Author SHA1 Message Date
Sky Young
f1ef06879e
Merge pull request #1 from oipwg/update-fcoin
Update fcoin to 1.1.0
2019-07-25 10:40:50 -06:00
Sky Young
c44229feed Update fcoin version to 1.1.0 2019-07-25 10:38:21 -06:00
Sky Young
e334370777 Use new class based function checking instead of prototypal checking 2019-07-25 09:01:30 -06:00
Sky Young
d1034b3a82 Use proper Transaction import 2019-07-25 08:48:41 -06:00
Sky Young
1b1ef05ada Add fcoin to package.json 2019-07-24 12:57:00 -06:00
Sky Young
dae4c318c2 Properly deserialize Block using fcoin 2019-07-24 12:56:36 -06:00
Sky Young
a062769cc4 Update flocore-lib 2019-07-23 11:10:25 -06:00
Sky Young
f3cdb94450 Update fcoin 2019-07-19 15:09:09 -06:00
Sky Young
25adf9f18f Update version 2018-05-18 17:54:22 -07:00
Sky Young
14f3c30ad3 'bitcore-lib' -> 'flocore-lib' 2018-05-15 14:58:33 -07:00
Sky Young
335bd996b5 Update package references 2018-05-15 14:52:30 -07:00
Sky Young
c898c3bc50 Update Packages 2018-04-30 12:12:50 -07:00
Chris Kleeschulte
10a21524d8
Bumped version. 2017-08-29 16:20:04 -04:00
Chris Kleeschulte
c8e273aefe
Fixed tests so that Bitcore Blocks/Txs and Bcoin Blocks/Txs can be used
in tests and code.
2017-08-21 14:03:05 -04:00
Jason Dreyzehner
8d756c6c56 chore(release): 5.0.0-beta.1 2017-08-18 19:00:28 -04:00
Jason Dreyzehner
0e333f3248 Merge remote-tracking branch 'upstream/bcoin' 2017-08-18 18:51:34 -04:00
Jason Dreyzehner
d7970b2553 chore(package): use transitional bitcore-lib 2017-08-15 16:12:43 -04:00
Chris Kleeschulte
5de3ca9eab Merge pull request #94 from gabegattis/dependency/bcoin
change bcoin dependency to 1.0.0-beta.12
2017-07-21 13:09:19 -04:00
Gabe Gattis
2fd4cbf622
change bcoin dependency to 1.0.0-beta.12 2017-07-21 12:50:04 -04:00
Chris Kleeschulte
f537eb86b9
bcoin tx and blocks support. 2017-07-21 09:05:56 -04:00
Chris Kleeschulte
59fbc03715
Bumped version. 2017-04-24 18:45:14 -04:00
Chris Kleeschulte
1ad1eed82a Merge pull request #93 from kleetus/updates/protocol
Default protocol and bitcore-lib updates
2017-04-24 18:37:23 -04:00
Chris Kleeschulte
c41681d6c2
Default protocol and bitcore-lib updates
- Default protocol should be 70001 instead of 70000 since there really
was no protocol in the 70000 series.
2017-04-24 17:47:38 -04:00
Matias Alejo Garcia
b7a6845a4f Update .travis.yml 2017-03-15 13:15:07 -03:00
Chris Kleeschulte
96c10c27ea Bumped version to v1.1.1. 2017-01-13 17:12:37 -05:00
Patrick Nagurny
e684688e4d Merge pull request #90 from kleetus/master
Dependency on substack's node-buffers
2017-01-13 15:07:13 -05:00
Chris Kleeschulte
8de9d91ee9 Dependency on substack's node-buffers
- Long-standing deprecation on Array.get has expired, node v6 no longer
supports this.
- Upstream project has not yet merged #17, therefore we must fork and
change this project's dependency.
2017-01-12 18:01:55 -05:00
Braydon Fuller
7bb9afd416 Bump package version to 1.1.0 2015-12-23 10:36:59 -05:00
Braydon Fuller
4d9f52ec98 Merge pull request #77 from smh/feature/reject-message
Implemented Reject message
2015-12-23 10:31:44 -05:00
Stein Martin Hustad
55242db152 Removed old commented code 2015-12-16 00:00:30 +01:00
Stein Martin Hustad
dbda30d4d1 Fix spacing 2015-12-16 00:00:30 +01:00
Stein Martin Hustad
0ea205d0eb Fix bug in Request.getPayload()
Apparently, node v0.12 buffer.writeUInt8 is more lenient than v0.10
2015-12-16 00:00:30 +01:00
Stein Martin Hustad
6a88aaae9b Add test for Reject message 2015-12-16 00:00:30 +01:00
Stein Martin Hustad
1dfdd66b72 Allow attributes in constructor 2015-12-16 00:00:30 +01:00
Stein Martin Hustad
576ba8a2b6 Implement Reject message 2015-12-16 00:00:30 +01:00
Braydon Fuller
5b2d3691cb Merge pull request #79 from bitjson/master
format
2015-11-17 22:41:30 -05:00
Jason Dreyzehner
c81875f014 Merge branch 'master' of github.com:bitpay/bitcore-p2p 2015-11-17 18:55:38 -05:00
Braydon Fuller
d2eeb5e09e Merge pull request #80 from unusualbob/fixTypos
Fix typos in docs
2015-10-22 11:55:46 -04:00
Rob Riddle
d951cbb3ba Fix typos in docs 2015-10-22 18:52:49 +03:00
Jason Dreyzehner
3a19287da1 format 2015-10-20 09:20:39 -04:00
Braydon Fuller
d13da49c87 Bump package version to 1.0.0 2015-10-16 16:30:47 -04:00
40 changed files with 2606 additions and 140 deletions

View File

@ -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

View File

@ -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();
```

View File

@ -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:

View File

@ -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:

View File

@ -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.

View File

@ -1,4 +1,4 @@
var bitcore = require('bitcore-lib');
var bitcore = require('flocore-lib');
bitcore.P2P = require('./lib');
module.exports = bitcore.P2P;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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: {

View File

@ -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._;

View File

@ -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;

View File

@ -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();
};

View File

@ -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;

View File

@ -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;
/**

View File

@ -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;

View File

@ -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;
/**

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
/**

View File

@ -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._;

View File

@ -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;

View File

@ -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._;

View File

@ -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._;

View File

@ -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;

View File

@ -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();
};

View File

@ -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;
/**

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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._;

View File

@ -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();

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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": {

View File

@ -34,7 +34,7 @@
"message": "f9beb4d9616c65727400000000000000bc0000004fe68fe973010000003766404f00000000b305434f00000000f2030000f1030000001027000048ee00000064000000004653656520626974636f696e2e6f72672f666562323020696620796f7520686176652074726f75626c6520636f6e6e656374696e67206166746572203230204665627275617279004730450221008389df45f0703f39ec8c1cc42c13810ffcae14995bb648340219e353b63b53eb022009ec65e1c1aaeec1fd334c6b684bde2b3f573060d5b70c3a46723326e4e8a4f1"
},
"reject": {
"message": "f9beb4d972656a656374000000000000000000005df6e0e2"
"message": "f9beb4d972656a6563740000000000003a000000f44033160274780015696e73756666696369656e74207072696f72697479165d408c9dd26fbdcb42b07546f6c37752301e3772f3ae441baf569e78839111"
},
"notfound": {
"message": "f9beb4d96e6f74666f756e6400000000250000001d33d53201010000003a4af715be220eae7b2657582869daddf79ac4afb4a0e1cafa5b57e1afb8dfe2"

View File

@ -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();