Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time remaining estimate and minor fixes #56

Merged
merged 10 commits into from May 18, 2014

support peer blocklist

  • Loading branch information
transitive-bullshit committed May 16, 2014
commit 196d9eee696f101b664c6c64e2531080ac24576d
@@ -17,8 +17,9 @@ inherits(WebTorrent, Client)

function WebTorrent (opts) {
var self = this
opts = opts || {}
if (opts.blocklist) opts.blocklist = parseBlocklist(opts.blocklist)

This comment has been minimized.

Copy link
@feross

feross May 18, 2014

Member

tab -> spaces

This comment has been minimized.

Copy link
@transitive-bullshit

transitive-bullshit May 18, 2014

Author Member

good call

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

This comment has been minimized.

Copy link
@feross

feross May 18, 2014

Member

thanks for adding this!

// 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
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.