hypercore-protocol
Advanced tools
Comparing version 7.0.0 to 7.1.0
11
index.js
@@ -413,8 +413,11 @@ const SHP = require('simple-hypercore-protocol') | ||
close (key) { | ||
const discoveryKey = crypto.discoveryKey(key) | ||
close (discoveryKey) { | ||
const ch = this.channelizer.getChannel(discoveryKey) | ||
if (ch) ch.close() | ||
else this.state.close(this.channelizer.allocLocal(), { discoveryKey }) | ||
if (ch && ch.localId > -1) { | ||
ch.close() | ||
return | ||
} | ||
this.state.close(this.channelizer.allocLocal(), { discoveryKey }) | ||
} | ||
@@ -421,0 +424,0 @@ |
{ | ||
"name": "hypercore-protocol", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"description": "Stream that implements the hypercore protocol", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -117,2 +117,7 @@ # hypercore-protocol | ||
#### `stream.close(discoveryKey)` | ||
You can call this method to signal to the other side that you do not have the key | ||
corresponding to the discoveryKey. Normally you would use this together with the `ondiscoverykey` hook. | ||
#### `stream.destroy([error])` | ||
@@ -119,0 +124,0 @@ |
18
test.js
@@ -430,1 +430,19 @@ const tape = require('tape') | ||
}) | ||
tape('can close by discovery key', function (t) { | ||
const a = new Protocol(true) | ||
const b = new Protocol(false, { | ||
ondiscoverykey (discoveryKey) { | ||
b.close(discoveryKey) | ||
} | ||
}) | ||
a.open(KEY, { | ||
onclose () { | ||
t.pass('channel closed') | ||
t.end() | ||
} | ||
}) | ||
a.pipe(b).pipe(a) | ||
}) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
32852
791
258
0