-
-
Notifications
You must be signed in to change notification settings - Fork 335
Expose swarm object on tracker server #218
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
146d4d4
Extension point on requests and responses
yciabaud 1efb832
Remove debug log
yciabaud 8482c3a
Add extra data on ws annouce event
yciabaud f65983e
do not filter out extra keys from 'update' events
feross ee9ebc5
remove requestHandler option
feross 992cd77
expose Swarm object for easy overriding
feross 51b57f6
test: remove UDP request handler test -- not possible
feross 0c683df
test: change request handler test to new approach
feross a77873a
Merge pull request #1 from feross/feross/request-handler-changes
yciabaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| var Buffer = require('safe-buffer').Buffer | ||
| var Client = require('../') | ||
| var common = require('./common') | ||
| var fixtures = require('webtorrent-fixtures') | ||
| var test = require('tape') | ||
| var Server = require('../server') | ||
|
|
||
| var peerId = Buffer.from('01234567890123456789') | ||
|
|
||
| function testRequestHandler (t, serverType) { | ||
| t.plan(5) | ||
|
|
||
| var opts = { serverType: serverType } // this is test-suite-only option | ||
|
|
||
| class Swarm extends Server.Swarm { | ||
| announce (params, cb) { | ||
| super.announce(params, function (err, response) { | ||
| if (err) return cb(response) | ||
| response.complete = 246 | ||
| response.extraData = 'hi' | ||
| cb(null, response) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Use a custom Swarm implementation for this test only | ||
| var OldSwarm = Server.Swarm | ||
| Server.Swarm = Swarm | ||
| t.on('end', function () { | ||
| Server.Swarm = OldSwarm | ||
| }) | ||
|
|
||
| common.createServer(t, opts, function (server, announceUrl) { | ||
| var client1 = new Client({ | ||
| infoHash: fixtures.alice.parsedTorrent.infoHash, | ||
| announce: announceUrl, | ||
| peerId: peerId, | ||
| port: 6881, | ||
| wrtc: {} | ||
| }) | ||
|
|
||
| client1.on('error', function (err) { t.error(err) }) | ||
| if (serverType === 'ws') common.mockWebsocketTracker(client1) | ||
|
|
||
| server.once('start', function () { | ||
| t.pass('got start message from client1') | ||
| }) | ||
|
|
||
| client1.once('update', function (data) { | ||
| t.equal(data.complete, 246) | ||
| t.equal(data.extraData.toString(), 'hi') | ||
|
|
||
| client1.destroy(function () { | ||
| t.pass('client1 destroyed') | ||
| }) | ||
|
|
||
| server.close(function () { | ||
| t.pass('server destroyed') | ||
| }) | ||
| }) | ||
|
|
||
| client1.start() | ||
| }) | ||
| } | ||
|
|
||
| test('http: request handler option intercepts announce requests and responses', function (t) { | ||
| testRequestHandler(t, 'http') | ||
| }) | ||
|
|
||
| test('ws: request handler option intercepts announce requests and responses', function (t) { | ||
| testRequestHandler(t, 'ws') | ||
| }) | ||
|
|
||
| // NOTE: it's not possible to include extra data in a UDP response, because it's compact and accepts only params that are in the spec! | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding tests.