Browse Source

Connection, const: add bits necessary for getheaders/headers

patch-2
Jeff Garzik 12 years ago
parent
commit
5b69342356
  1. 22
      Connection.js
  2. 7
      const.js

22
Connection.js

@ -187,7 +187,7 @@ function spec(b) {
this.sendMessage('version', put.buffer());
};
Connection.prototype.sendGetBlocks = function (starts, stop) {
Connection.prototype.sendGetBlocks = function (starts, stop, wantHeaders) {
var put = new Put();
put.word32le(this.sendVer);
@ -207,7 +207,14 @@ function spec(b) {
put.put(stopBuffer);
this.sendMessage('getblocks', put.buffer());
var command = 'getblocks';
if (wantHeaders)
command = 'getheaders';
this.sendMessage(command, put.buffer());
};
Connection.prototype.sendGetHeaders = function(starts, stop) {
this.sendGetBlocks(starts, stop, true);
};
Connection.prototype.sendGetData = function (invs) {
@ -432,6 +439,17 @@ function spec(b) {
}
break;
case 'headers':
data.count = parser.varInt();
data.headers = [];
for (i = 0; i < data.count; i++) {
var header = new Block();
header.parse(parser);
data.headers.push(header);
}
break;
case 'block':
var block = new Block();
block.parse(parser);

7
const.js

@ -0,0 +1,7 @@
exports.MSG = {
TX: 1,
BLOCK: 2,
FILTERED_BLOCK: 3,
};
Loading…
Cancel
Save