working on fixing Version
This commit is contained in:
parent
17e890996e
commit
c8674a8633
@ -83,9 +83,11 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('handles addr', function(cb) {
|
||||
it.only('handles addr', function(cb) {
|
||||
connect(function(peer) {
|
||||
peer.once('addr', function(message) {
|
||||
console.log(message.serialize(network).toString('hex'));
|
||||
console.log(message.getPayload().toString('hex'));
|
||||
message.addresses.forEach(function(address) {
|
||||
// console.log(address.ip.v4 + ':' + address.port);
|
||||
(address.time instanceof Date).should.equal(true);
|
||||
@ -98,7 +100,7 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
|
||||
peer.sendMessage(message);
|
||||
});
|
||||
});
|
||||
it('can request inv detailed info', function(cb) {
|
||||
it('requests inv detailed info', function(cb) {
|
||||
connect(function(peer) {
|
||||
peer.once('block', function(message) {
|
||||
//console.log(message.block.toJSON());
|
||||
@ -116,7 +118,7 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('can send tx inv and receive getdata for that tx', function(cb) {
|
||||
it('sends tx inv and receives getdata for that tx', function(cb) {
|
||||
connect(function(peer) {
|
||||
var type = Messages.Inventory.TYPE.TX;
|
||||
var inv = [{
|
||||
@ -133,7 +135,7 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
|
||||
peer.sendMessage(message);
|
||||
});
|
||||
});
|
||||
it('can request block data', function(cb) {
|
||||
it('requests block data', function(cb) {
|
||||
connect(function(peer) {
|
||||
peer.once('block', function(message) {
|
||||
(message.block instanceof Block).should.equal(true);
|
||||
@ -144,7 +146,7 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
|
||||
});
|
||||
});
|
||||
var fakeHash = 'e2dfb8afe1575bfacae1a0b4afc49af7ddda69285857267bae0e22be15f74a3a';
|
||||
it('can handle request tx data not found', function(cb) {
|
||||
it('handles request tx data not found', function(cb) {
|
||||
connect(function(peer) {
|
||||
var expected = Messages.NotFound.forTransaction(fakeHash);
|
||||
peer.once('notfound', function(message) {
|
||||
@ -158,7 +160,7 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
|
||||
});
|
||||
var from = [blockHash[network.name]];
|
||||
var stop = stopBlock[network.name];
|
||||
it('can get headers', function(cb) {
|
||||
it('gets headers', function(cb) {
|
||||
connect(function(peer) {
|
||||
peer.once('headers', function(message) {
|
||||
(message instanceof Messages.Headers).should.equal(true);
|
||||
@ -169,7 +171,7 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
|
||||
peer.sendMessage(message);
|
||||
});
|
||||
});
|
||||
it('can get blocks', function(cb) {
|
||||
it('gets blocks', function(cb) {
|
||||
connect(function(peer) {
|
||||
peer.once('inv', function(message) {
|
||||
(message instanceof Messages.Inventory).should.equal(true);
|
||||
@ -182,7 +184,20 @@ describe('Integration with ' + network.name + ' bitcoind', function() {
|
||||
peer.sendMessage(message);
|
||||
});
|
||||
});
|
||||
it('can send inv and respond with info', function(cb) {
|
||||
it('sends inv and responds with info', function(cb) {
|
||||
connect(function(peer) {
|
||||
var randomHash = Random.getRandomBuffer(32);// needs to be random for repeatability
|
||||
var expected = Messages.GetData.forBlock(randomHash);
|
||||
peer.once('getdata', function(message) {
|
||||
(message instanceof Messages.GetData).should.equal(true);
|
||||
message.should.deep.equal(expected);
|
||||
cb();
|
||||
});
|
||||
var message = Messages.Inventory.forBlock(randomHash);
|
||||
peer.sendMessage(message);
|
||||
});
|
||||
});
|
||||
it('aasdasd', function(cb) {
|
||||
connect(function(peer) {
|
||||
var randomHash = Random.getRandomBuffer(32);// needs to be random for repeatability
|
||||
var expected = Messages.GetData.forBlock(randomHash);
|
||||
|
||||
@ -209,15 +209,29 @@ Version.prototype.fromBuffer = function(payload) {
|
||||
*/
|
||||
this.timestamp = new Date(parser.readUInt64LEBN().toNumber() * 1000);
|
||||
/**
|
||||
* @type {Buffer}
|
||||
* @type {object}
|
||||
* @desc IPv4/6 address of the interface used to connect to this peer
|
||||
*/
|
||||
this.addr_me = parser.read(26);
|
||||
var me_services = parser.readUInt64LEBN();
|
||||
var me_ip = Addresses.parseIP(parser);
|
||||
var me_port = parser.readUInt16BE();
|
||||
this.addr_me = {
|
||||
services: me_services,
|
||||
ip: me_ip,
|
||||
port: me_port
|
||||
};
|
||||
/**
|
||||
* @type {Buffer}
|
||||
* @type {object}
|
||||
* @desc IPv4/6 address of the peer
|
||||
*/
|
||||
this.addr_you = parser.read(26);
|
||||
var your_services = parser.readUInt64LEBN();
|
||||
var your_ip = Addresses.parseIP(parser);
|
||||
var your_port = parser.readUInt16BE();
|
||||
this.addr_you = {
|
||||
services: your_services,
|
||||
ip: your_ip,
|
||||
port: your_port
|
||||
};
|
||||
/**
|
||||
* @type {Buffer}
|
||||
* @desc A random number
|
||||
@ -227,23 +241,31 @@ Version.prototype.fromBuffer = function(payload) {
|
||||
* @desc The node's user agent / subversion
|
||||
* @type {string}
|
||||
*/
|
||||
this.subversion = parser.readVarintBuf().toString();
|
||||
this.subversion = parser.readVarLengthBuffer().toString();
|
||||
/**
|
||||
* @desc The height of the last block accepted in the blockchain by this peer
|
||||
* @type {number}
|
||||
*/
|
||||
this.start_height = parser.readUInt32LE();
|
||||
|
||||
console.log(this);
|
||||
$.checkState(parser.finished());
|
||||
return this;
|
||||
};
|
||||
|
||||
Version.writeAddr = function(addr, parser) {
|
||||
parser.word64le(addr.services);
|
||||
parser.put(addr.ip);
|
||||
parser.word16be(addr.port);
|
||||
};
|
||||
|
||||
Version.prototype.getPayload = function() {
|
||||
var put = new Put();
|
||||
put.word32le(this.version); // version
|
||||
put.word32le(this.version);
|
||||
put.word64le(1); // services
|
||||
put.word64le(Math.round(new Date().getTime() / 1000)); // timestamp
|
||||
put.pad(26); // addr_me
|
||||
put.pad(26); // addr_you
|
||||
Version.writeAddr(this.addr_me, put);
|
||||
Version.writeAddr(this.addr_you, put);
|
||||
put.put(this.nonce);
|
||||
put.varint(this.subversion.length);
|
||||
put.put(new Buffer(this.subversion, 'ascii'));
|
||||
@ -315,6 +337,7 @@ Inventory.prototype.fromBuffer = function(payload) {
|
||||
this.inventory.push(Inventory.forItem(type, hash));
|
||||
}
|
||||
|
||||
$.checkState(parser.finished());
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -396,7 +419,9 @@ function Ping(nonce) {
|
||||
util.inherits(Ping, Message);
|
||||
|
||||
Ping.prototype.fromBuffer = function(payload) {
|
||||
this.nonce = new BufferReader(payload).read(8);
|
||||
var parser = new BufferReader(payload);
|
||||
this.nonce = parser.read(8);
|
||||
$.checkState(parser.finished());
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -422,9 +447,6 @@ function Pong(nonce) {
|
||||
}
|
||||
|
||||
util.inherits(Pong, Ping);
|
||||
Pong.prototype.fromBuffer = function() {
|
||||
return new Pong();
|
||||
};
|
||||
module.exports.Pong = Message.COMMANDS.pong = Pong;
|
||||
|
||||
/**
|
||||
@ -474,9 +496,7 @@ Addresses.prototype.fromBuffer = function(payload) {
|
||||
|
||||
var time = new Date(parser.readUInt32LE() * 1000);
|
||||
var services = parser.readUInt64LEBN();
|
||||
|
||||
var ip = Addresses.parseIP(parser);
|
||||
|
||||
var port = parser.readUInt16BE();
|
||||
|
||||
this.addresses.push({
|
||||
@ -487,6 +507,7 @@ Addresses.prototype.fromBuffer = function(payload) {
|
||||
});
|
||||
}
|
||||
|
||||
$.checkState(parser.finished());
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -559,8 +580,9 @@ util.inherits(Alert, Message);
|
||||
|
||||
Alert.prototype.fromBuffer = function(payload) {
|
||||
var parser = new BufferReader(payload);
|
||||
this.payload = parser.readVarintBuf(); // TODO: Use current format
|
||||
this.signature = parser.readVarintBuf();
|
||||
this.payload = parser.readVarLengthBuffer();
|
||||
this.signature = parser.readVarLengthBuffer();
|
||||
$.checkState(parser.finished());
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -604,7 +626,7 @@ Headers.prototype.fromBuffer = function(payload) {
|
||||
var header = BlockHeaderModel.fromBufferReader(parser);
|
||||
this.headers.push(header);
|
||||
}
|
||||
|
||||
$.checkState(parser.finished());
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -730,6 +752,7 @@ GetBlocks.prototype.fromBuffer = function(payload) {
|
||||
this.starts.push(parser.read(32));
|
||||
}
|
||||
this.stop = parser.read(32);
|
||||
$.checkState(parser.finished());
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
"url": "https://github.com/bitpay/bitcore-p2p.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"bitcore": "^0.9.0",
|
||||
"bitcore": "^0.9.5",
|
||||
"bufferput": "^0.1.2",
|
||||
"buffers": "^0.1.1",
|
||||
"socks5-client": "^0.3.6"
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
},
|
||||
"ALERT": {
|
||||
"message": "",
|
||||
"payload": ""
|
||||
"payload": "73010000003766404f00000000b305434f00000000f2030000f1030000001027000048ee00000064000000004653656520626974636f696e2e6f72672f666562323020696620796f7520686176652074726f75626c6520636f6e6e656374696e67206166746572203230204665627275617279004730450221008389df45f0703f39ec8c1cc42c13810ffcae14995bb648340219e353b63b53eb022009ec65e1c1aaeec1fd334c6b684bde2b3f573060d5b70c3a46723326e4e8a4f1"
|
||||
},
|
||||
"REJECT": {
|
||||
"message": "",
|
||||
|
||||
@ -31,7 +31,7 @@ describe('Messages', function() {
|
||||
NotFound: 'notfound'
|
||||
};
|
||||
// TODO: add data for these
|
||||
var noPayload = ['Alert', 'Reject', 'GetBlocks', 'GetHeaders'];
|
||||
var noPayload = ['Reject', 'GetBlocks', 'GetHeaders'];
|
||||
var names = Object.keys(commands);
|
||||
describe('named', function() {
|
||||
names.forEach(function(name) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user