pool: add ban and unban calls once again.

This commit is contained in:
Christopher Jeffrey 2016-12-21 15:12:14 -08:00
parent cc4dd23c83
commit 14f2851929
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 32 additions and 15 deletions

View File

@ -545,7 +545,7 @@ RPC.prototype.ping = co(function* ping(args) {
});
RPC.prototype.setban = co(function* setban(args) {
var addr, peer;
var addr;
if (args.help
|| args.length < 2
@ -555,20 +555,14 @@ RPC.prototype.setban = co(function* setban(args) {
}
addr = toString(args[0]);
addr = IP.parseHost(addr, this.network);
addr = NetAddress.fromHostname(addr, this.network);
switch (args[1]) {
case 'add':
peer = this.pool.peers.get(addr.hostname);
if (peer) {
peer.ban();
break;
}
this.pool.hosts.ban(addr.host);
this.pool.hosts.remove(addr.hostname);
this.pool.ban(addr);
break;
case 'remove':
this.pool.hosts.unban(addr.host);
this.pool.unban(addr);
break;
}

View File

@ -35,7 +35,7 @@ var VerifyResult = errors.VerifyResult;
* @exports Peer
* @constructor
* @param {Pool} pool
* @param {NetAddress} addr
* @param {NetAddress} address
* @param {net.Socket?} socket
* @property {Pool} pool
* @property {net.Socket?} socket
@ -2685,10 +2685,7 @@ Peer.prototype.increaseBan = function increaseBan(score) {
*/
Peer.prototype.ban = function ban() {
this.logger.debug('Banning peer (%s).', this.hostname);
this.pool.hosts.ban(this.host);
this.pool.hosts.remove(this.hostname);
this.destroy();
this.pool.ban(this.address);
};
/**

View File

@ -1668,6 +1668,32 @@ Pool.prototype.removePeer = function removePeer(peer) {
}
};
/**
* Ban peer.
* @param {NetAddress} addr
*/
Pool.prototype.ban = function ban(addr) {
var peer = this.peers.get(addr.hostname);
this.logger.debug('Banning peer (%s).', addr.hostname);
this.hosts.ban(addr.host);
this.hosts.remove(addr.hostname);
if (peer)
peer.destroy();
};
/**
* Unban peer.
* @param {NetAddress} addr
*/
Pool.prototype.unban = function unban(addr) {
this.hosts.unban(addr.host);
};
/**
* Set the spv filter.
* @param {Bloom} filter