Browse Source

Merge pull request #224 from olalonde/peer-improvements

Some improvements on PeerManager and Connection classes
patch-2
Ryan X. Charles 11 years ago
parent
commit
acd7909e43
  1. 7
      Connection.js
  2. 5
      PeerManager.js

7
Connection.js

@ -186,10 +186,15 @@ Connection.prototype.sendVersion = function () {
}; };
Connection.prototype.sendGetBlocks = function (starts, stop, wantHeaders) { Connection.prototype.sendGetBlocks = function (starts, stop, wantHeaders) {
// Default value for stop is 0 to get as many blocks as possible (500)
stop = stop || util.NULL_HASH;
var put = new Put(); var put = new Put();
put.word32le(this.sendVer);
// https://en.bitcoin.it/wiki/Protocol_specification#getblocks
put.word32le(this.sendVer);
put.varint(starts.length); put.varint(starts.length);
for (var i = 0; i < starts.length; i++) { for (var i = 0; i < starts.length; i++) {
if (starts[i].length != 32) { if (starts[i].length != 32) {
throw new Error('Invalid hash length'); throw new Error('Invalid hash length');

5
PeerManager.js

@ -111,6 +111,9 @@ PeerManager.prototype.addConnection = function(socketConn, peer) {
}; };
PeerManager.prototype.handleVersion = function(e) { PeerManager.prototype.handleVersion = function(e) {
e.peer.version = e.message.version;
e.peer.start_height = e.message.start_height;
if (!e.conn.inbound) { if (!e.conn.inbound) {
// TODO: Advertise our address (if listening) // TODO: Advertise our address (if listening)
} }
@ -132,7 +135,7 @@ PeerManager.prototype.handleReady = function (e) {
}); });
if(this.isConnected == false) { if(this.isConnected == false) {
this.emit('netConnected'); this.emit('netConnected', e);
this.isConnected = true; this.isConnected = true;
} }
}; };

Loading…
Cancel
Save