bittorrent-protocol
Advanced tools
Comparing version 1.1.0 to 1.2.0
11
index.js
@@ -141,2 +141,3 @@ module.exports = Wire | ||
this._ext[Extension.name] = handler | ||
this[Extension.name] = handler | ||
@@ -146,12 +147,2 @@ this._nextExt += 1 | ||
/** | ||
* Return an extension's exported functions | ||
* @param {string} ext extension name | ||
* @return {Object} | ||
*/ | ||
Wire.prototype.ext = function (ext) { | ||
var self = this | ||
return this._ext[ext] | ||
} | ||
// | ||
@@ -158,0 +149,0 @@ // OUTGOING MESSAGES |
{ | ||
"name": "bittorrent-protocol", | ||
"description": "Simple, robust, BitTorrent peer wire protocol implementation", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Feross Aboukhadijeh", |
@@ -213,7 +213,7 @@ # bittorrent-protocol [![build](http://img.shields.io/travis/feross/bittorrent-protocol.svg)](https://travis-ci.org/feross/bittorrent-protocol) [![npm](http://img.shields.io/npm/v/bittorrent-protocol.svg)](https://npmjs.org/package/bittorrent-protocol) [![gittip](http://img.shields.io/gittip/feross.svg)](https://www.gittip.com/feross/) | ||
This package, **bittorrent-protocol**, also provides a plugin API to make it easy to | ||
integrate extensions that use the extension protocol (BEP 10) into this module. For | ||
example, to support ut_metadata (BEP 9), you need only install the | ||
This package, **bittorrent-protocol**, also provides an extension API to make it easy to | ||
add extensions to this module using the "extension protocol" (BEP 10). For example, to | ||
support ut_metadata (BEP 9), you need only install the | ||
[ut_metadata](https://github.com/feross/ut_metadata) npm module and call `wire.use()`. | ||
See the [Plugin API](#plugin-api) section for more information. | ||
See the [Extension API](#extension-api) section for more information. | ||
@@ -240,19 +240,25 @@ ### transfer stats | ||
## plugin api | ||
## extension api | ||
This package supports a simple plugin API so you can extend the default protocol | ||
This package supports a simple extension API so you can extend the default protocol | ||
functionality with common protocol extensions like ut_metadata (magnet uris). | ||
Here are the **bittorrent-protocol** plugins that we know about: | ||
Here are the **bittorrent-protocol** extensions that we know about: | ||
- [ut_metadata](https://github.com/feross/ut_metadata) | ||
- **Add yours here! (Send a pull request! | ||
- [ut_metadata](https://github.com/feross/ut_metadata) - Extension for Peers to Send Metadata Files (BEP 9) | ||
- *Add yours here! Send a pull request!* | ||
In short, a plugin can register itself with at a certain name, which will be added to the | ||
extended protocol handshake sent to the remote peer. Plugins can also hook events like | ||
'handshake' and 'extended'. To use a plugin, simply require it and call `wire.use()`. | ||
In short, an extension can register itself with at a certain name, which will be added to | ||
the extended protocol handshake sent to the remote peer. Extensions can also hook events | ||
like 'handshake' and 'extended'. To use an extension, simply require it and call | ||
`wire.use()`. | ||
Here is an example of the **ut_metadata** plugin being used with **bittorrent-protocol**: | ||
Here is an example of the **ut_metadata** extension being used with | ||
**bittorrent-protocol**: | ||
```js | ||
var Protocol = require('bittorrent-protocol') | ||
var net = require('net') | ||
var ut_metadata = require('ut_metadata') | ||
net.createServer(function (socket) { | ||
@@ -265,9 +271,9 @@ var wire = new Protocol() | ||
// all `ut_metadata` functionality can now be accessed at wire.ext('ut_metadata') | ||
// all `ut_metadata` functionality can now be accessed at wire.ut_metadata | ||
// ask the peer to send us metadata | ||
wire.ext('ut_metadata').fetch() | ||
wire.ut_metadata.fetch() | ||
// 'metadata' event will fire when the metadata arrives and is verified to be correct! | ||
wire.ext('ut_metadata').on('metadata', function (metadata) { | ||
wire.ut_metadata.on('metadata', function (metadata) { | ||
// got metadata! | ||
@@ -282,3 +288,3 @@ | ||
// probably not going to arrive for one of the above reasons. | ||
wire.ext('ut_metadata').on('warning', function (err) { | ||
wire.ut_metadata.on('warning', function (err) { | ||
console.log(err.message) | ||
@@ -295,3 +301,3 @@ }) | ||
If you want to write your own plugin, take a look at the | ||
If you want to write your own extension, take a look at the | ||
[ut_metadata index.js file](https://github.com/feross/ut_metadata/blob/master/index.js) | ||
@@ -298,0 +304,0 @@ to see how it's done. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34254
306
751