Merge pull request #224 from olalonde/peer-improvements
Some improvements on PeerManager and Connection classes
This commit is contained in:
commit
acd7909e43
@ -186,10 +186,15 @@ Connection.prototype.sendVersion = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Connection.prototype.sendGetBlocks = function (starts, stop, wantHeaders) {
|
Connection.prototype.sendGetBlocks = function (starts, stop, wantHeaders) {
|
||||||
var put = new Put();
|
// Default value for stop is 0 to get as many blocks as possible (500)
|
||||||
put.word32le(this.sendVer);
|
stop = stop || util.NULL_HASH;
|
||||||
|
|
||||||
|
var put = new Put();
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
|||||||
@ -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…
Reference in New Issue
Block a user