hypercore 10.0.0-alpha.17 → 10.0.0-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -92,9 +92,27 @@ module.exports = class Hypercore extends EventEmitter {
92
92
  indent + ')'
93
93
  }
94
94
 
95
- static createProtocolStream (isInitiator, opts) {
96
- const noiseStream = new NoiseSecretStream(isInitiator, null, opts)
97
- return noiseStream.rawStream
95
+ static createProtocolStream (isInitiator, opts = {}) {
96
+ let outerStream = isStream(isInitiator)
97
+ ? isInitiator
98
+ : opts.stream
99
+ let noiseStream = null
100
+
101
+ if (outerStream) {
102
+ noiseStream = outerStream.noiseStream
103
+ } else {
104
+ noiseStream = new NoiseSecretStream(isInitiator, null, opts)
105
+ outerStream = noiseStream.rawStream
106
+ }
107
+ if (!noiseStream) throw new Error('Invalid stream')
108
+
109
+ if (!noiseStream.userData) {
110
+ const protocol = Replicator.createProtocol(noiseStream)
111
+ noiseStream.userData = protocol
112
+ noiseStream.on('error', noop) // All noise errors already propagate through outerStream
113
+ }
114
+
115
+ return outerStream
98
116
  }
99
117
 
100
118
  static defaultStorage (storage, opts = {}) {
@@ -268,33 +286,17 @@ module.exports = class Hypercore extends EventEmitter {
268
286
  }
269
287
 
270
288
  replicate (isInitiator, opts = {}) {
271
- let outerStream = isStream(isInitiator)
272
- ? isInitiator
273
- : opts.stream
274
- let noiseStream = null
275
-
276
- if (outerStream) {
277
- noiseStream = outerStream.noiseStream
278
- } else {
279
- outerStream = Hypercore.createProtocolStream(isInitiator, opts)
280
- noiseStream = outerStream.noiseStream
281
- }
282
- if (!noiseStream) throw new Error('Invalid stream passed to replicate')
283
-
284
- if (!noiseStream.userData) {
285
- const protocol = Replicator.createProtocol(noiseStream)
286
- noiseStream.userData = protocol
287
- noiseStream.on('error', noop) // All noise errors already propagate through outerStream
288
- }
289
-
289
+ const protocolStream = Hypercore.createProtocolStream(isInitiator, opts)
290
+ const noiseStream = protocolStream.noiseStream
290
291
  const protocol = noiseStream.userData
292
+
291
293
  if (this.opened) {
292
294
  this.replicator.joinProtocol(protocol, this.key, this.discoveryKey)
293
295
  } else {
294
296
  this.opening.then(() => this.replicator.joinProtocol(protocol, this.key, this.discoveryKey), protocol.destroy.bind(protocol))
295
297
  }
296
298
 
297
- return outerStream
299
+ return protocolStream
298
300
  }
299
301
 
300
302
  get length () {
package/lib/protocol.js CHANGED
@@ -39,7 +39,7 @@ class Extension {
39
39
  _sendAlias (message, alias) {
40
40
  if (this.destroyed) return
41
41
 
42
- if (this._remoteAliases) {
42
+ if (this.remoteSupports) {
43
43
  return this.protocol.send(this.type, this.encoding, alias, message)
44
44
  }
45
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.0.0-alpha.17",
3
+ "version": "10.0.0-alpha.18",
4
4
  "description": "Hypercore 10",
5
5
  "main": "index.js",
6
6
  "scripts": {