Gordon Hall
11 years ago
3 changed files with 81 additions and 1 deletions
@ -0,0 +1,47 @@ |
|||
'use strict'; |
|||
var imports = require('soop').imports(); |
|||
var parent = imports.parent || require('events').EventEmitter; |
|||
var EventEmitter = require('events').EventEmitter; |
|||
var dns = require('dns'); |
|||
var inherits = require('util').inherits; |
|||
|
|||
function SeedList(options) { |
|||
this.options = options || {}; |
|||
this.sources = [ |
|||
'dnsseed.bluematt.me', |
|||
'dnsseed.bitcoin.dashjr.org', |
|||
'seed.bitcoin.sipa.be', |
|||
'seed.bitcoinstats.com', |
|||
'bitseed.xf2.org' |
|||
]; |
|||
this.source = this.options.source || this.sources[0]; |
|||
this.seeds = []; |
|||
this.find() |
|||
}; |
|||
|
|||
inherits(SeedList, EventEmitter); |
|||
|
|||
SeedList.prototype.find = function() { |
|||
var self = this; |
|||
dns.resolve(self.source, function(err, seeds) { |
|||
if (err) { |
|||
var index = self.sources.indexOf(self.source); |
|||
if (index !== -1) { |
|||
index++; |
|||
if (!self.sources[index]) { |
|||
return self.emit('seedsNotFound'); |
|||
} |
|||
else { |
|||
self.source = self.sources[index]; |
|||
} |
|||
self.find(); |
|||
} |
|||
return self.emit('error', err); |
|||
} |
|||
self.seeds = self.seeds.concat(seeds); |
|||
self.emit('seedsFound', seeds); |
|||
}); |
|||
return self; |
|||
}; |
|||
|
|||
module.exports = require('soop')(SeedList); |
@ -1,4 +1,4 @@ |
|||
module.exports = { |
|||
network: 'livenet', |
|||
logger: 'normal' // none, normal, debug
|
|||
logger: 'debug' // none, normal, debug
|
|||
}; |
|||
|
@ -0,0 +1,33 @@ |
|||
var Socks5Client = require('socks5-client'); |
|||
var Peer = require('../Peer'); |
|||
var Connection = require('../Connection'); |
|||
var SeedList = require('../SeedList') |
|||
|
|||
// start looking for a seed
|
|||
var seedlist = new SeedList(); |
|||
// create a client socket proxied through
|
|||
// tor's socks5 proxy
|
|||
var client = new Socks5Client('127.0.0.1', 9050); |
|||
|
|||
// when we have a list of seeds...
|
|||
seedlist.on('seedsFound', function(seeds) { |
|||
// use the first seed in list
|
|||
var peer = new Peer(seeds[0], 8333); |
|||
var connection = new Connection(client, peer); |
|||
// open the connection to the seed
|
|||
client.connect(peer.port, peer.host); |
|||
// always handle errors
|
|||
connection.on('error', function(err) { |
|||
console.log(err); |
|||
}); |
|||
}); |
|||
|
|||
// failboat
|
|||
seedlist.on('seedsNotFound', function() { |
|||
console.log('failed to find seeds :('); |
|||
}); |
|||
|
|||
// double failboat
|
|||
seedlist.on('error', function(err) { |
|||
console.log('error:', err); |
|||
}); |
Loading…
Reference in new issue