hypercore-protocol-substream
Advanced tools
Comparing version 2.0.6 to 2.0.7
13
index.js
@@ -17,7 +17,7 @@ const _debug = require('debug') | ||
const RETRY_INTERVAL = 500 | ||
const RETRY_INTERVAL = 300 | ||
class SubstreamRouter { | ||
constructor (feed) { | ||
this.id = randbytes() | ||
this.id = randbytes(2).hexSlice() | ||
this.subs = [] | ||
@@ -61,3 +61,3 @@ this._ridTable = {} | ||
_onDestroyed () { | ||
this.feed.off('extension', this._onExtension) | ||
this.feed.removeListener('extension', this._onExtension) | ||
delete this.feed.__subrouter | ||
@@ -105,3 +105,3 @@ | ||
const randbytes = () => Buffer.from(Math.floor((1 << 24) * Math.random()).toString(16), 'hex') | ||
const randbytes = (n) => Buffer.from(Array.from(new Array(n)).map(i => Math.floor(0xff * Math.random()))) | ||
class SubStream extends Duplex { | ||
@@ -113,3 +113,3 @@ constructor (feed, name, opts = {}) { | ||
this.name = name || randbytes() | ||
this.name = name || randbytes(32) | ||
this.state = INIT | ||
@@ -121,3 +121,3 @@ this.lastError = null | ||
this.debug = _debug(`substream/R ${this.router.id.hexSlice(0, 2)} S ${this.id}`) | ||
this.debug = _debug(`substream/R ${this.router.id} S ${this.id}`) | ||
this.debug('Initializing new substream') | ||
@@ -266,3 +266,2 @@ } | ||
// Install router into feed if missing. | ||
@@ -269,0 +268,0 @@ if (!feed.__subrouter) { |
{ | ||
"name": "hypercore-protocol-substream", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "Create independent virtual streams on a hypercore-protocol stream", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,3 +26,3 @@ # hypercore-protocol-substream | ||
// Create a primary feed with an encryption key | ||
const virtualFeed = protocol.feed(key) | ||
const virtualFeed = stream.feed(key) | ||
@@ -29,0 +29,0 @@ // Initialize new virtual stream as namespace 'beef' |
25174