Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfisch0920 <fisch0920@gmail.com>2014-05-16 13:08:01 +0400
committerfisch0920 <fisch0920@gmail.com>2014-05-16 13:08:01 +0400
commit196d9eee696f101b664c6c64e2531080ac24576d (patch)
treef9bea6f6d789823c38f44aa991e6c331733f646d /index.js
parentd6d66ecccc175351a1a4af6aad3c3f8362f22173 (diff)
support peer blocklist
Diffstat (limited to 'index.js')
-rw-r--r--index.js26
1 files changed, 24 insertions, 2 deletions
diff --git a/index.js b/index.js
index 2e6fe56..5b96eb8 100644
--- a/index.js
+++ b/index.js
@@ -17,8 +17,9 @@ inherits(WebTorrent, Client)
function WebTorrent (opts) {
var self = this
+ opts = opts || {}
+ if (opts.blocklist) opts.blocklist = parseBlocklist(opts.blocklist)
Client.call(self, opts)
- if (!opts) opts = {}
if (opts.list) {
return
@@ -88,7 +89,6 @@ WebTorrent.prototype._onTorrent = function (torrent) {
var self = this
// if no index specified, use largest file
- // TODO: support torrent index selection correctly -- this doesn't work yet
if (typeof torrent.index !== 'number') {
var largestFile = torrent.files.reduce(function (a, b) {
return a.length > b.length ? a : b
@@ -158,3 +158,25 @@ WebTorrent.prototype._onRequest = function (req, res) {
}
pump(file.createReadStream(range), res)
}
+
+//
+// HELPER METHODS
+//
+
+function parseBlocklist (filename) {
+ // TODO: support gzipped files
+ var blocklistData = fs.readFileSync(filename, { encoding: 'utf8' })
+ var blocklist = []
+ blocklistData.split('\n').forEach(function(line) {
+ var match = null
+ if ((match = /^\s*([^#].*)\s*:\s*([a-f0-9.:]+?)\s*-\s*([a-f0-9.:]+?)\s*$/.exec(line))) {
+ blocklist.push({
+ reason: match[1],
+ startAddress: match[2],
+ endAddress: match[3]
+ })
+ }
+ })
+ return blocklist
+}
+