hypercore-protocol
Advanced tools
Comparing version 8.0.0 to 8.0.1
20
index.js
@@ -52,2 +52,14 @@ const SHP = require('simple-hypercore-protocol') | ||
detachChannel (ch) { | ||
if (ch.localId > -1 && this.local[ch.localId] === ch) { | ||
this.local[ch.localId] = null | ||
} | ||
if (ch.remoteId > -1 && this.remote[ch.remoteId] === ch) { | ||
this.remote[ch.remoteId] = null | ||
} | ||
const hex = ch.discoveryKey.toString('hex') | ||
if (this.created.get(hex) === ch) this.created.delete(hex) | ||
} | ||
getChannel (dk) { | ||
@@ -98,2 +110,5 @@ return this.created.get(dk.toString('hex')) | ||
if (ch.handlers && ch.handlers.onopen) ch.handlers.onopen() | ||
if (this.stream.handlers.onremoteopen) this.stream.handlers.onremoteopen(ch.discoveryKey) | ||
this.stream.emit('remote-open', ch.discoveryKey) | ||
} | ||
@@ -183,3 +198,3 @@ | ||
if (ch.localId > -1) { | ||
if (ch.localId > -1 && this.local[ch.localId] === ch) { | ||
this.local[ch.localId] = null | ||
@@ -305,3 +320,6 @@ } | ||
if (this.closed) return | ||
this.stream.channelizer.detachChannel(this) | ||
this.state.close(this.localId, {}) | ||
this.stream._prefinalize() | ||
} | ||
@@ -308,0 +326,0 @@ |
{ | ||
"name": "hypercore-protocol", | ||
"version": "8.0.0", | ||
"version": "8.0.1", | ||
"description": "Stream that implements the hypercore protocol", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# hypercore-protocol | ||
Stream that implements the [hypercore](https://github.com/mafintosh/hypercore) protocol | ||
Stream that implements the [hypercore](https://github.com/hypercore-protocol/hypercore) protocol | ||
@@ -9,3 +9,3 @@ ``` | ||
[![build status](https://travis-ci.org/mafintosh/hypercore-protocol.svg?branch=master)](https://travis-ci.org/mafintosh/hypercore-protocol) | ||
[![build status](https://travis-ci.org/hypercore-protocol/hypercore-protocol.svg?branch=master)](https://travis-ci.org/hypercore-protocol/hypercore-protocol) | ||
@@ -12,0 +12,0 @@ For detailed info on the messages sent on each channel see [simple-hypercore-protocol](https://github.com/mafintosh/simple-hypercore-protocol) |
25
test.js
@@ -606,1 +606,26 @@ const tape = require('tape') | ||
}) | ||
tape('open and close and open same channel', function (t) { | ||
const a = new Protocol(true) | ||
const b = new Protocol(false, { | ||
ondiscoverykey (dkey) { | ||
b.open(KEY) | ||
} | ||
}) | ||
const ch1 = a.open(KEY, { | ||
onopen () { | ||
t.pass('remote open #1') | ||
ch1.close() | ||
a.open(KEY, { | ||
onopen () { | ||
t.pass('remote open #2') | ||
t.end() | ||
} | ||
}) | ||
} | ||
}) | ||
a.pipe(b).pipe(a) | ||
}) |
42079
1051