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

Added pause/resume, refactored code, improved command line interface (and more) #515

Closed
wants to merge 31 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
53d6335
got tests for pause/resume to pass
whitef0x0 Nov 27, 2015
cd1d84c
added nice cli for seed quitting interface
whitef0x0 Nov 27, 2015
61d1afb
added resume/pause support for audio/video streaming
whitef0x0 Nov 27, 2015
c68d39d
got gracefulExit to stop hanging
whitef0x0 Nov 27, 2015
67c9c47
added disableSeeding option for torrent
whitef0x0 Nov 27, 2015
01a685a
added getBySearch method
whitef0x0 Nov 27, 2015
b003801
added documentation for getBySearch
whitef0x0 Nov 27, 2015
9f4768f
fixed cli for search
whitef0x0 Nov 27, 2015
9ceac78
added tests for addBySearch()
whitef0x0 Nov 27, 2015
2415418
got all tests to pass but one
whitef0x0 Nov 30, 2015
be0b718
got download /path/to/file cmd.js test to pass
whitef0x0 Dec 1, 2015
b1430c8
updated browser code
whitef0x0 Dec 2, 2015
3db0dad
fixed cmd
whitef0x0 Dec 2, 2015
488bcc9
updated minified build
whitef0x0 Dec 2, 2015
10f9cc2
added unit tests for torrent.js
whitef0x0 Dec 3, 2015
53ea5f1
added tests for appendTo
whitef0x0 Dec 4, 2015
af023ce
added .npmignore
whitef0x0 Dec 4, 2015
74382ee
got zuul tests to run
whitef0x0 Dec 4, 2015
341ed30
removed extraneous user stories
whitef0x0 Dec 4, 2015
428a9ac
added documentation for new methods to the README
whitef0x0 Dec 4, 2015
8752393
added test cli interface
whitef0x0 Dec 5, 2015
2737d3f
updated travis-ci build
whitef0x0 Dec 5, 2015
9067381
started travis-ci
whitef0x0 Dec 5, 2015
254eae0
fixed package.json and travis.yml; got travis-ci to pass
whitef0x0 Dec 5, 2015
7f03f39
added main property to bower.json
whitef0x0 Dec 5, 2015
cb9849c
added ignore to bower.json
whitef0x0 Dec 5, 2015
d82559d
removed search functionality
whitef0x0 Dec 5, 2015
7610325
removed bower
whitef0x0 Dec 5, 2015
4d44ccd
Create description.md
whitef0x0 Dec 11, 2015
9f56b0c
Update test.js
whitef0x0 Dec 11, 2015
82fffad
Added description of changes
whitef0x0 Dec 11, 2015
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

added nice cli for seed quitting interface

  • Loading branch information
whitef0x0 committed Nov 27, 2015
commit cd1d84ce23c71f0c2fece2186b805208650dfabe
@@ -345,6 +345,7 @@ function runDownload (torrentId) {
return a.length > b.length ? a : b
}))


if (argv.select) {
var interactive = process.stdin.isTTY && !!process.stdin.setRawMode
if (interactive) {
@@ -493,118 +494,182 @@ function runSeed (input) {
}

var drawInterval
var commandMode = false
var lastInput = ''
var blockDraw = false
var cliInput = false


function drawTorrent (torrent) {

process.stdin.on('data', function(chunk) {
blockDraw = true

if (chunk === 'q' || chunk === 's') {
cliInput = true
process.stdin.setRawMode(false)
process.stdin.pause();
var cli = inquirer.prompt([{
type: 'input',
name: 'shouldQuit',
validate: function(input) {
if (input === 'y' || input === 'n') {
// Pass the return value in the done callback
return true
}else{
return "Incorrect input. Please enter 'y' or 'n'"
}
},
filter: function( input ) {
if(input === 'y') return true
else if(input === 'n') return false
},
message: 'Do you wish to stop seeding?',
}], function (answers) {
if(answers.shouldQuit){
clearInterval(drawInterval)
drawInterval.unref()
gracefulExit()
}else{
process.stdin.setRawMode(true)
blockDraw = false
cliInput = false
}
})

cli.rl.on('SIGINT', function () {
return gracefulExit()
})
}else if(!cliInput){
setTimeout(function(){
blockDraw = false
draw()
},100)
}
});

if (!argv.quiet) {

process.stdout.write(new Buffer('G1tIG1sySg==', 'base64')) // clear for drawing
process.stdin.setRawMode(true)
process.stdin.resume()
process.stdin.setEncoding( 'utf8' );
drawInterval = setInterval(draw, 500)
drawInterval.unref()

}

function draw () {
var hotswaps = 0
torrent.on('hotswap', function () {
hotswaps += 1
})

var unchoked = torrent.swarm.wires.filter(function (wire) {
return !wire.peerChoking
})
var linesRemaining = clivas.height
var peerslisted = 0
var speed = torrent.downloadSpeed()
var estimate = moment.duration(torrent.timeRemaining / 1000, 'seconds').humanize()

clivas.clear()

if (playerName) {
clivas.line('{green:Streaming to} {bold:' + playerName + '}')
linesRemaining -= 1
}
if(!blockDraw){
var hotswaps = 0
torrent.on('hotswap', function () {
hotswaps += 1
})

if (server) {
clivas.line('{green:server running at} {bold:' + href + '}')
linesRemaining -= 1
}
var unchoked = torrent.swarm.wires.filter(function (wire) {
return !wire.peerChoking
})
var linesRemaining = clivas.height
var peerslisted = 0
var speed = torrent.downloadSpeed()
var estimate = moment.duration(torrent.timeRemaining / 1000, 'seconds').humanize()

if (argv.out) {
clivas.line('{green:downloading to} {bold:' + argv.out + '}')
linesRemaining -= 1
}
clivas.clear()

var seeding = torrent.done
if (playerName) {
clivas.line('{green:Streaming to} {bold:' + playerName + '}')
linesRemaining -= 1
}

if (!seeding) clivas.line('')
clivas.line(
'{green:' + (seeding ? 'seeding' : 'downloading') + ':} ' +
'{bold:' + torrent.name + '}'
)
if (seeding) {
clivas.line('{green:info hash:} ' + torrent.infoHash)
linesRemaining -= 1
}
clivas.line(
'{green:speed: }{bold:' + prettyBytes(speed) + '/s} ' +
'{green:downloaded:} {bold:' + prettyBytes(torrent.downloaded) + '}' +
'/{bold:' + prettyBytes(torrent.length) + '} ' +
'{green:uploaded:} {bold:' + prettyBytes(torrent.uploaded) + '} ' +
'{green:peers:} {bold:' + unchoked.length + '/' + torrent.swarm.wires.length + '} ' +
'{green:hotswaps:} {bold:' + hotswaps + '}'
)
clivas.line(
'{green:time remaining:} {bold:' + estimate + ' remaining} ' +
'{green:total time:} {bold:' + getRuntime() + 's} ' +
'{green:queued peers:} {bold:' + torrent.swarm.numQueued + '} ' +
'{green:blocked:} {bold:' + torrent.numBlockedPeers + '}'
)
clivas.line('{80:}')
linesRemaining -= 5

torrent.swarm.wires.every(function (wire) {
var progress = '?'
if (torrent.length) {
var bits = 0
var piececount = Math.ceil(torrent.length / torrent.pieceLength)
for (var i = 0; i < piececount; i++) {
if (wire.peerPieces.get(i)) {
bits++
}
}
progress = bits === piececount ? 'S' : Math.floor(100 * bits / piececount) + '%'
if (server) {
clivas.line('{green:server running at} {bold:' + href + '}')
linesRemaining -= 1
}
var tags = []

if (wire.peerChoking) tags.push('choked')
if (wire.requests.length > 0) tags.push(wire.requests.length + ' reqs')
if (argv.out) {
clivas.line('{green:downloading to} {bold:' + argv.out + '}')
linesRemaining -= 1
}

var reqStats = argv.verbose
? wire.requests.map(function (req) { return req.piece })
: []
var seeding = torrent.done

if (!seeding) clivas.line('')
clivas.line(
'{3:%s} {25+magenta:%s} {10:%s} {12+cyan:%s/s} {12+red:%s/s} {15+grey:%s}' +
'{10+grey:%s}',
progress,
wire.remoteAddress
? (wire.remoteAddress + ':' + wire.remotePort)
: 'Unknown',
prettyBytes(wire.downloaded),
prettyBytes(wire.downloadSpeed()),
prettyBytes(wire.uploadSpeed()),
tags.join(', '),
reqStats.join(' ')
'{green:' + (seeding ? 'seeding' : 'downloading') + ':} ' +
'{bold:' + torrent.name + '}'
)
peerslisted++
return linesRemaining - peerslisted > 4
})
linesRemaining -= peerslisted
if (seeding) {
clivas.line('{green:info hash:} ' + torrent.infoHash)
linesRemaining -= 1
}
clivas.line(
'{green:speed: }{bold:' + prettyBytes(speed) + '/s} ' +
'{green:downloaded:} {bold:' + prettyBytes(torrent.downloaded) + '}' +
'/{bold:' + prettyBytes(torrent.length) + '} ' +
'{green:uploaded:} {bold:' + prettyBytes(torrent.uploaded) + '} ' +
'{green:peers:} {bold:' + unchoked.length + '/' + torrent.swarm.wires.length + '} ' +
'{green:hotswaps:} {bold:' + hotswaps + '}'
)
clivas.line(
'{green:time remaining:} {bold:' + estimate + ' remaining} ' +
'{green:total time:} {bold:' + getRuntime() + 's} ' +
'{green:queued peers:} {bold:' + torrent.swarm.numQueued + '} ' +
'{green:blocked:} {bold:' + torrent.numBlockedPeers + '}'
)
clivas.line('{80:}')
linesRemaining -= 5

torrent.swarm.wires.every(function (wire) {
var progress = '?'
if (torrent.length) {
var bits = 0
var piececount = Math.ceil(torrent.length / torrent.pieceLength)
for (var i = 0; i < piececount; i++) {
if (wire.peerPieces.get(i)) {
bits++
}
}
progress = bits === piececount ? 'S' : Math.floor(100 * bits / piececount) + '%'
}
var tags = []

if (wire.peerChoking) tags.push('choked')
if (wire.requests.length > 0) tags.push(wire.requests.length + ' reqs')

var reqStats = argv.verbose
? wire.requests.map(function (req) { return req.piece })
: []

clivas.line(
'{3:%s} {25+magenta:%s} {10:%s} {12+cyan:%s/s} {12+red:%s/s} {15+grey:%s}' +
'{10+grey:%s}',
progress,
wire.remoteAddress
? (wire.remoteAddress + ':' + wire.remotePort)
: 'Unknown',
prettyBytes(wire.downloaded),
prettyBytes(wire.downloadSpeed()),
prettyBytes(wire.uploadSpeed()),
tags.join(', '),
reqStats.join(' ')
)
peerslisted++
return linesRemaining - peerslisted > 4
})
linesRemaining -= peerslisted

if (torrent.swarm.wires.length > peerslisted) {
clivas.line('{80:}')
clivas.line('... and %s more', torrent.swarm.wires.length - peerslisted)
}

if (torrent.swarm.wires.length > peerslisted) {
clivas.line('{80:}')
clivas.line('... and %s more', torrent.swarm.wires.length - peerslisted)
}

clivas.line('{80:}')
clivas.flush(true)
if(commandMode){
clivas.line('{green:command :}')
}
clivas.flush(true)
}
}
}

@@ -223,6 +223,7 @@ Torrent.prototype._onParsedTorrent = function (parsedTorrent) {
})

self.swarm.on('upload', function (uploaded) {
self.emit('seed request')
self.client.uploadSpeed(uploaded) // update overall client stats
self.client.emit('upload', uploaded)
self.emit('upload', uploaded)
@@ -235,6 +236,7 @@ Torrent.prototype._onParsedTorrent = function (parsedTorrent) {


process.nextTick(function () {
self.emit('seed request')
if (self.destroyed || self.paused) return
self.emit('infoHash', self.infoHash)
})
@@ -407,18 +409,13 @@ Torrent.prototype._onMetadata = function (metadata) {

self._onWireWithMetadata(wire)
})
//console.log('initial progress: '+self.progress);
}else{
//console.log('RESUMING')
//console.log('resumed progress: '+self.progress);
}

self.files = self.files.map(function (file) {
return new File(self, file)
})

debug('verifying existing torrent data')
self.emit('verifying')
parallel(self.pieces.map(function (piece, index) {
return function (cb) {
self.store.get(index, function (err, buf) {
@@ -660,6 +657,7 @@ Torrent.prototype.critical = function (start, end) {
Torrent.prototype._onWire = function (wire, addr) {
var self = this
debug('got wire (%s)', addr || 'Unknown')
self.emit('seed request')

//console.log('got wire (%s)', addr || 'Unknown')

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