Commit Graph

16 Commits

Author SHA1 Message Date
Feross Aboukhadijeh
0aadcc1cbb Wait up to 1s for pending requests before destroy()
If the user calls:

client.stop()
client.destroy()

We should ensure that the final 'stopped' message reaches the tracker
server, even though the client will not get the response (because they
destroyed the client and no more events will be emitted).

If there are pending requests when destroy() is called, then a 1s timer
is set after which point all requests are forcibly cleaned up. If the
requests complete before the 1s timer fires, then cleanup happens right
away (so we're not stuck waiting for the 1s timer).

So, destroy() can happen one of three ways:

- immediately, if no pending requests exist
- after exactly 1s, if pending requests exist and they don't complete
within 1s
- less than 1s, if pending requests exist and they all complete before
the 1s timer fires
2017-01-20 18:41:28 -08:00
Feross Aboukhadijeh
a35f1f8178 replace hat with randombytes 2016-08-20 19:37:36 -07:00
Feross Aboukhadijeh
2959c2cea6 Use safe-buffer
Use the new Buffer APIs from Node v6 for added security. For example,
`Buffer.from()` will throw if passed a number, unlike `Buffer()` which
allocated UNINITIALIZED memory in that case.

Use the `safe-buffer` package for compatibility with previous versions
of
Node.js, including v4.x, v0.12, and v0.10.

https://github.com/feross/safe-buffer
2016-05-29 23:12:23 -07:00
Feross Aboukhadijeh
2966165a8f BREAKING: Client() takes single opts object now
To use the client, you used to pass in four arguments:

`new Client(peerId, port, parsedTorrent, opts)`

Now, passing in the torrent is no longer required, just the `announce`
and `infoHash` properties. This decouples this package from
`parse-torrent`.

All options get passed in together now:

new Client({
infoHash: '', // hex string or Buffer
peerId: '', // hex string or Buffer
announce: [], // list of tracker server urls
port: 6881 // torrent client port, (in browser, optional)
})

All the normal optional arguments (rtcConfig, wrtc, etc.) can still be
passed in with the rest of these options.

Fixes #118. Fixes #115.

Added ws tests for scrape.
2016-03-31 21:37:51 -07:00
Feross Aboukhadijeh
6df64ffe06 Fixes for PR #126 2016-03-14 19:16:00 -07:00
Autarc
09e2b55e42 invoke callbacks of destroyed trackers 2016-03-14 17:13:34 +01:00
Feross Aboukhadijeh
b34fc100a1 fixes for PR #107 2016-02-29 12:34:06 -08:00
Yoann Ciabaud
f1669a506e Provide a way to give updated announce opts via callback on setInterval 2016-02-03 08:28:38 +01:00
Feross Aboukhadijeh
177171b82c expose client.peerId and client.peerIdBuffer 2015-12-02 22:33:15 -08:00
Feross Aboukhadijeh
d344537766 expose client.infoHash and client.infoHashBuffer 2015-12-02 15:46:41 -08:00
Feross Aboukhadijeh
38a80093a1 Fix UDP scrape returning invalid info hashes (Fix #97) 2015-12-02 15:35:42 -08:00
Feross Aboukhadijeh
e9322a32d6 code style 2015-12-02 15:31:20 -08:00
Aram Drevekenin
ab3482fc4f Changed infoHash to always be hex 2015-11-29 16:02:29 +02:00
Feross Aboukhadijeh
f5d2810c89 Announce to websocket tracker every 30 seconds (for #338) 2015-07-29 02:12:14 -07:00
Feross Aboukhadijeh
9db28c2fad massive cleanup 2015-07-29 01:47:09 -07:00
Feross Aboukhadijeh
3746c05d79 restructure folders 2015-07-29 00:26:44 -07:00