peer: refactor ack handling.
This commit is contained in:
parent
7606667ea5
commit
6a87a9588b
@ -566,6 +566,9 @@ Peer.prototype.announceBlock = function announceBlock(blocks) {
|
|||||||
var inv = [];
|
var inv = [];
|
||||||
var i, block;
|
var i, block;
|
||||||
|
|
||||||
|
if (!this.ack)
|
||||||
|
return;
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -614,7 +617,10 @@ Peer.prototype.announceBlock = function announceBlock(blocks) {
|
|||||||
|
|
||||||
Peer.prototype.announceTX = function announceTX(txs) {
|
Peer.prototype.announceTX = function announceTX(txs) {
|
||||||
var inv = [];
|
var inv = [];
|
||||||
var i, tx, entry;
|
var i, tx, hash, entry;
|
||||||
|
|
||||||
|
if (!this.ack)
|
||||||
|
return;
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
return;
|
||||||
@ -640,7 +646,8 @@ Peer.prototype.announceTX = function announceTX(txs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.feeRate !== -1 && this.mempool) {
|
if (this.feeRate !== -1 && this.mempool) {
|
||||||
entry = this.mempool.getEntry(tx.hash('hex'));
|
hash = tx.hash('hex');
|
||||||
|
entry = this.mempool.getEntry(hash);
|
||||||
if (entry && entry.getRate() < this.feeRate)
|
if (entry && entry.getRate() < this.feeRate)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -693,6 +700,9 @@ Peer.prototype.announceList = function announceList() {
|
|||||||
Peer.prototype.sendInv = function sendInv(items) {
|
Peer.prototype.sendInv = function sendInv(items) {
|
||||||
var i, item, chunk;
|
var i, item, chunk;
|
||||||
|
|
||||||
|
if (!this.ack)
|
||||||
|
return;
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -724,6 +734,9 @@ Peer.prototype.sendInv = function sendInv(items) {
|
|||||||
Peer.prototype.sendHeaders = function sendHeaders(items) {
|
Peer.prototype.sendHeaders = function sendHeaders(items) {
|
||||||
var i, item, chunk;
|
var i, item, chunk;
|
||||||
|
|
||||||
|
if (!this.ack)
|
||||||
|
return;
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -794,6 +807,9 @@ Peer.prototype.sendPing = function sendPing() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Peer.prototype.updateWatch = function updateWatch() {
|
Peer.prototype.updateWatch = function updateWatch() {
|
||||||
|
if (!this.ack)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!this.options.spv)
|
if (!this.options.spv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -806,6 +822,9 @@ Peer.prototype.updateWatch = function updateWatch() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Peer.prototype.sendFeeRate = function sendFeeRate(rate) {
|
Peer.prototype.sendFeeRate = function sendFeeRate(rate) {
|
||||||
|
if (!this.ack)
|
||||||
|
return;
|
||||||
|
|
||||||
this.send(new packets.FeeFilterPacket(rate));
|
this.send(new packets.FeeFilterPacket(rate));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -866,6 +885,8 @@ Peer.prototype.destroy = function destroy() {
|
|||||||
entry.destroy();
|
entry.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.locker.destroy();
|
||||||
|
|
||||||
this.emit('close');
|
this.emit('close');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2451,6 +2472,9 @@ Peer.prototype.handleBlockTxn = co(function* handleBlockTxn(packet) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Peer.prototype.sendAlert = function sendAlert(alert) {
|
Peer.prototype.sendAlert = function sendAlert(alert) {
|
||||||
|
if (!this.ack)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!this.invFilter.added(alert.hash()))
|
if (!this.invFilter.added(alert.hash()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -2523,6 +2547,9 @@ Peer.prototype.sendGetBlocks = function getBlocks(locator, stop) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Peer.prototype.sendMempool = function sendMempool() {
|
Peer.prototype.sendMempool = function sendMempool() {
|
||||||
|
if (!this.ack)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!this.version)
|
if (!this.version)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@ -87,7 +87,6 @@ var VerifyResult = errors.VerifyResult;
|
|||||||
* @emits Pool#version
|
* @emits Pool#version
|
||||||
* @emits Pool#ack
|
* @emits Pool#ack
|
||||||
* @emits Pool#watched
|
* @emits Pool#watched
|
||||||
* @emits Pool#leech
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Pool(options) {
|
function Pool(options) {
|
||||||
@ -439,7 +438,7 @@ Pool.prototype.listen = function listen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.server.on('connection', function(socket) {
|
this.server.on('connection', function(socket) {
|
||||||
self.handleLeech(socket);
|
self.handleInbound(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.server.on('listening', function() {
|
this.server.on('listening', function() {
|
||||||
@ -480,7 +479,7 @@ Pool.prototype.unlisten = function unlisten() {
|
|||||||
* @param {net.Socket} socket
|
* @param {net.Socket} socket
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Pool.prototype.handleLeech = function handleLeech(socket) {
|
Pool.prototype.handleInbound = function handleInbound(socket) {
|
||||||
var addr;
|
var addr;
|
||||||
|
|
||||||
if (!socket.remoteAddress) {
|
if (!socket.remoteAddress) {
|
||||||
@ -706,7 +705,7 @@ Pool.prototype.sync = function sync() {
|
|||||||
var peer;
|
var peer;
|
||||||
|
|
||||||
for (peer = this.peers.head(); peer; peer = peer.next) {
|
for (peer = this.peers.head(); peer; peer = peer.next) {
|
||||||
if (!peer.outbound || !peer.ack)
|
if (!peer.outbound)
|
||||||
continue;
|
continue;
|
||||||
peer.sync();
|
peer.sync();
|
||||||
}
|
}
|
||||||
@ -721,7 +720,7 @@ Pool.prototype.forceSync = function forceSync() {
|
|||||||
var peer;
|
var peer;
|
||||||
|
|
||||||
for (peer = this.peers.head(); peer; peer = peer.next) {
|
for (peer = this.peers.head(); peer; peer = peer.next) {
|
||||||
if (!peer.outbound || !peer.ack)
|
if (!peer.outbound)
|
||||||
continue;
|
continue;
|
||||||
peer.syncSent = false;
|
peer.syncSent = false;
|
||||||
peer.sync();
|
peer.sync();
|
||||||
@ -747,7 +746,7 @@ Pool.prototype.stopSync = co(function* stopSync() {
|
|||||||
this.stopTimeout();
|
this.stopTimeout();
|
||||||
|
|
||||||
for (peer = this.peers.head(); peer; peer = peer.next) {
|
for (peer = this.peers.head(); peer; peer = peer.next) {
|
||||||
if (!peer.outbound || !peer.ack)
|
if (!peer.outbound)
|
||||||
continue;
|
continue;
|
||||||
peer.syncSent = false;
|
peer.syncSent = false;
|
||||||
}
|
}
|
||||||
@ -760,11 +759,8 @@ Pool.prototype.stopSync = co(function* stopSync() {
|
|||||||
Pool.prototype.sendMempool = function sendMempool() {
|
Pool.prototype.sendMempool = function sendMempool() {
|
||||||
var peer;
|
var peer;
|
||||||
|
|
||||||
for (peer = this.peers.head(); peer; peer = peer.next) {
|
for (peer = this.peers.head(); peer; peer = peer.next)
|
||||||
if (!peer.ack)
|
|
||||||
continue;
|
|
||||||
peer.sendMempool();
|
peer.sendMempool();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -775,11 +771,8 @@ Pool.prototype.sendMempool = function sendMempool() {
|
|||||||
Pool.prototype.sendAlert = function sendAlert(alert) {
|
Pool.prototype.sendAlert = function sendAlert(alert) {
|
||||||
var peer;
|
var peer;
|
||||||
|
|
||||||
for (peer = this.peers.head(); peer; peer = peer.next) {
|
for (peer = this.peers.head(); peer; peer = peer.next)
|
||||||
if (!peer.ack)
|
|
||||||
continue;
|
|
||||||
peer.sendAlert(alert);
|
peer.sendAlert(alert);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -893,7 +886,7 @@ Pool.prototype.bindPeer = function bindPeer(peer) {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
peer.on('txs', function (txs) {
|
peer.on('txs', function(txs) {
|
||||||
self.handleTXInv(txs, peer);
|
self.handleTXInv(txs, peer);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1524,7 +1517,7 @@ Pool.prototype.addInbound = function addInbound(socket) {
|
|||||||
this.peers.add(peer);
|
this.peers.add(peer);
|
||||||
|
|
||||||
util.nextTick(function() {
|
util.nextTick(function() {
|
||||||
self.emit('leech', peer);
|
self.emit('peer', peer);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1657,11 +1650,8 @@ Pool.prototype.updateWatch = function updateWatch() {
|
|||||||
|
|
||||||
this.pendingWatch = setTimeout(function() {
|
this.pendingWatch = setTimeout(function() {
|
||||||
self.pendingWatch = null;
|
self.pendingWatch = null;
|
||||||
for (peer = self.peers.head(); peer; peer = peer.next) {
|
for (peer = self.peers.head(); peer; peer = peer.next)
|
||||||
if (!peer.ack)
|
|
||||||
continue;
|
|
||||||
peer.updateWatch();
|
peer.updateWatch();
|
||||||
}
|
|
||||||
}, 50);
|
}, 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1899,11 +1889,8 @@ Pool.prototype.broadcast = function broadcast(msg) {
|
|||||||
Pool.prototype.announceBlock = function announceBlock(msg) {
|
Pool.prototype.announceBlock = function announceBlock(msg) {
|
||||||
var peer;
|
var peer;
|
||||||
|
|
||||||
for (peer = this.peers.head(); peer; peer = peer.next) {
|
for (peer = this.peers.head(); peer; peer = peer.next)
|
||||||
if (!peer.ack)
|
|
||||||
continue;
|
|
||||||
peer.announceBlock(msg);
|
peer.announceBlock(msg);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1914,11 +1901,8 @@ Pool.prototype.announceBlock = function announceBlock(msg) {
|
|||||||
Pool.prototype.announceTX = function announceTX(msg) {
|
Pool.prototype.announceTX = function announceTX(msg) {
|
||||||
var peer;
|
var peer;
|
||||||
|
|
||||||
for (peer = this.peers.head(); peer; peer = peer.next) {
|
for (peer = this.peers.head(); peer; peer = peer.next)
|
||||||
if (!peer.ack)
|
|
||||||
continue;
|
|
||||||
peer.announceTX(msg);
|
peer.announceTX(msg);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1931,11 +1915,8 @@ Pool.prototype.setFeeRate = function setFeeRate(rate) {
|
|||||||
|
|
||||||
this.feeRate = rate;
|
this.feeRate = rate;
|
||||||
|
|
||||||
for (peer = this.peers.head(); peer; peer = peer.next) {
|
for (peer = this.peers.head(); peer; peer = peer.next)
|
||||||
if (!peer.ack)
|
|
||||||
continue;
|
|
||||||
peer.sendFeeRate(rate);
|
peer.sendFeeRate(rate);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user