get rid of wire.ext()

This commit is contained in:
Feross Aboukhadijeh 2014-03-26 02:03:13 -07:00
parent bb14f5990b
commit 9a30eb2ca2
3 changed files with 25 additions and 25 deletions

View File

@ -52,13 +52,13 @@ net.createServer(function (socket) {
// initialize the extension // initialize the extension
wire.use(ut_metadata()) wire.use(ut_metadata())
// 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 // 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! // '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! // got metadata!
// Note: the event will not fire if the peer does not support ut_metadata, if they // Note: the event will not fire if the peer does not support ut_metadata, if they
@ -68,7 +68,7 @@ net.createServer(function (socket) {
// optionally, listen to the 'warning' event if you want to know that metadata is // optionally, listen to the 'warning' event if you want to know that metadata is
// probably not going to arrive for one of the above reasons. // 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) console.log(err.message)
}) })
@ -87,7 +87,7 @@ net.createServer(function (socket) {
Ask the peer to send metadata. Ask the peer to send metadata.
```js ```js
wire.ext('ut_metadata').fetch() wire.ut_metadata.fetch()
``` ```
### cancel ### cancel
@ -95,7 +95,7 @@ wire.ext('ut_metadata').fetch()
Stop asking the peer to send metadata. Stop asking the peer to send metadata.
```js ```js
wire.ext('ut_metadata').cancel() wire.ut_metadata.cancel()
``` ```
### event: 'metadata' ### event: 'metadata'
@ -104,7 +104,7 @@ Fired when metadata is available and verified to be correct. Called with a singl
parameter of type Buffer. parameter of type Buffer.
```js ```js
wire.ext('ut_metadata').on('metadata', function (metadata) { wire.ut_metadata.on('metadata', function (metadata) {
console.log(Buffer.isBuffer(metadata)) // true console.log(Buffer.isBuffer(metadata)) // true
}) })
``` ```
@ -121,7 +121,7 @@ Fired if:
- the repeatedly sent invalid data - the repeatedly sent invalid data
```js ```js
wire.ext('ut_metadata').on('warning', function (err) { wire.ut_metadata.on('warning', function (err) {
console.log(err.message) console.log(err.message)
}) })
``` ```

View File

@ -12,10 +12,10 @@ test('wire.use(ut_metadata())', function (t) {
wire.use(ut_metadata()) wire.use(ut_metadata())
t.ok(wire.ext('ut_metadata')) t.ok(wire.ut_metadata)
t.ok(wire.ext('ut_metadata').fetch) t.ok(wire.ut_metadata.fetch)
t.ok(wire.ext('ut_metadata').cancel) t.ok(wire.ut_metadata.cancel)
t.notOk(wire.ext('ut_metadata').metadata) t.notOk(wire.ut_metadata.metadata)
t.end() t.end()
}) })
@ -25,9 +25,9 @@ test('wire.use(ut_metadata(metadata))', function (t) {
wire.use(ut_metadata(metadata)) wire.use(ut_metadata(metadata))
t.ok(wire.ext('ut_metadata')) t.ok(wire.ut_metadata)
t.ok(wire.ext('ut_metadata').fetch) t.ok(wire.ut_metadata.fetch)
t.ok(wire.ext('ut_metadata').cancel) t.ok(wire.ut_metadata.cancel)
t.equal(wire.ext('ut_metadata').metadata, metadata) t.equal(wire.ut_metadata.metadata, metadata)
t.end() t.end()
}) })

View File

@ -20,9 +20,9 @@ test('fetch()', function (t) {
wire1.use(ut_metadata(metadata)) // wire1 already has metadata wire1.use(ut_metadata(metadata)) // wire1 already has metadata
wire2.use(ut_metadata()) // wire2 does not wire2.use(ut_metadata()) // wire2 does not
wire2.ext('ut_metadata').fetch() wire2.ut_metadata.fetch()
wire2.ext('ut_metadata').on('metadata', function (_metadata) { wire2.ut_metadata.on('metadata', function (_metadata) {
// got metadata! // got metadata!
t.deepEqual(_metadata, metadata) t.deepEqual(_metadata, metadata)
}) })
@ -57,19 +57,19 @@ test('fetch() from peer without metadata', function (t) {
wire1.use(ut_metadata()) // neither wire has metadata wire1.use(ut_metadata()) // neither wire has metadata
wire2.use(ut_metadata()) wire2.use(ut_metadata())
wire2.ext('ut_metadata').fetch() wire2.ut_metadata.fetch()
wire2.ext('ut_metadata').on('metadata', function () { wire2.ut_metadata.on('metadata', function () {
t.fail('No "metadata" event should fire') t.fail('No "metadata" event should fire')
}) })
wire1.ext('ut_metadata').onMessage = function () { wire1.ut_metadata.onMessage = function () {
t.fail('No messages should be sent to wire1') t.fail('No messages should be sent to wire1')
// No messages should be sent because wire1 never sent metadata_size in the // No messages should be sent because wire1 never sent metadata_size in the
// extended handshake, so he doesn't have metadata // extended handshake, so he doesn't have metadata
} }
wire2.ext('ut_metadata').on('warning', function (err) { wire2.ut_metadata.on('warning', function (err) {
t.pass('got warning about peer missing metadata') t.pass('got warning about peer missing metadata')
}) })
@ -103,13 +103,13 @@ test('discard invalid metadata', function (t) {
wire1.use(ut_metadata(invalidMetadata)) wire1.use(ut_metadata(invalidMetadata))
wire2.use(ut_metadata()) wire2.use(ut_metadata())
wire2.ext('ut_metadata').fetch() wire2.ut_metadata.fetch()
wire2.ext('ut_metadata').on('metadata', function () { wire2.ut_metadata.on('metadata', function () {
t.fail('No "metadata" event should fire') t.fail('No "metadata" event should fire')
}) })
wire2.ext('ut_metadata').on('warning', function (err) { wire2.ut_metadata.on('warning', function (err) {
t.pass('got warning because peer sent reject too much') t.pass('got warning because peer sent reject too much')
}) })