update example, added log statements to status check in peer manager for showing how many good peers there are

This commit is contained in:
Gordon Hall 2014-04-20 14:31:07 -04:00
parent def036b79f
commit 9934b29eff
2 changed files with 9 additions and 2 deletions

View File

@ -1,4 +1,4 @@
var PeerManager = require('../lib/PeerManager');
var peerman = new PeerManager();
peerman.discover({ limit: 6 }).start();
peerman.discover({ limit: 12 }).start();

View File

@ -90,6 +90,13 @@ PeerManager.prototype.checkStatus = function checkStatus() {
}
});
// for debug purposes, print how many of our peers are actually connected
var connected = 0
this.peers.forEach(function(p) {
if (p.connection && !p.connection._connecting) connected++
});
log.info(connected + ' of ' + this.peers.length + ' peers connected');
Object.keys(peerIndex).forEach(function(i) {
this.connectTo(peerIndex[i]);
}.bind(this));
@ -192,8 +199,8 @@ PeerManager.prototype.handleDisconnect = function(e) {
if(i != -1) this.connections.splice(i, 1);
this.removePeer(e.peer);
log.info('replacing peer with one from the pool of: ' + this.pool.length);
if (this.pool.length) {
log.info('replacing peer using the pool of ' + this.pool.length + ' seeds');
this.addPeer(this.pool.pop());
}