@libp2p/interface-compliance-tests 2.0.1 → 3.0.0
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/README.md +19 -11
- package/dist/src/{utils/is-valid-tick.d.ts → is-valid-tick.d.ts} +0 -0
- package/dist/src/is-valid-tick.d.ts.map +1 -0
- package/dist/src/{utils/is-valid-tick.js → is-valid-tick.js} +0 -0
- package/dist/src/is-valid-tick.js.map +1 -0
- package/dist/src/{utils/peers.d.ts → peers.d.ts} +0 -0
- package/dist/src/peers.d.ts.map +1 -0
- package/dist/src/{utils/peers.js → peers.js} +0 -0
- package/dist/src/peers.js.map +1 -0
- package/package.json +11 -88
- package/src/{utils/is-valid-tick.ts → is-valid-tick.ts} +0 -0
- package/src/{utils/peers.ts → peers.ts} +0 -0
- package/dist/src/connection/connection.d.ts +0 -5
- package/dist/src/connection/connection.d.ts.map +0 -1
- package/dist/src/connection/connection.js +0 -146
- package/dist/src/connection/connection.js.map +0 -1
- package/dist/src/connection/index.d.ts +0 -5
- package/dist/src/connection/index.d.ts.map +0 -1
- package/dist/src/connection/index.js +0 -5
- package/dist/src/connection/index.js.map +0 -1
- package/dist/src/connection-encrypter/index.d.ts +0 -5
- package/dist/src/connection-encrypter/index.d.ts.map +0 -1
- package/dist/src/connection-encrypter/index.js +0 -77
- package/dist/src/connection-encrypter/index.js.map +0 -1
- package/dist/src/connection-encrypter/utils/index.d.ts +0 -3
- package/dist/src/connection-encrypter/utils/index.d.ts.map +0 -1
- package/dist/src/connection-encrypter/utils/index.js +0 -18
- package/dist/src/connection-encrypter/utils/index.js.map +0 -1
- package/dist/src/mocks/connection-encrypter.d.ts +0 -3
- package/dist/src/mocks/connection-encrypter.d.ts.map +0 -1
- package/dist/src/mocks/connection-encrypter.js +0 -93
- package/dist/src/mocks/connection-encrypter.js.map +0 -1
- package/dist/src/mocks/connection-gater.d.ts +0 -12
- package/dist/src/mocks/connection-gater.d.ts.map +0 -1
- package/dist/src/mocks/connection-gater.js +0 -14
- package/dist/src/mocks/connection-gater.js.map +0 -1
- package/dist/src/mocks/connection-manager.d.ts +0 -28
- package/dist/src/mocks/connection-manager.d.ts.map +0 -1
- package/dist/src/mocks/connection-manager.js +0 -107
- package/dist/src/mocks/connection-manager.js.map +0 -1
- package/dist/src/mocks/connection.d.ts +0 -18
- package/dist/src/mocks/connection.d.ts.map +0 -1
- package/dist/src/mocks/connection.js +0 -138
- package/dist/src/mocks/connection.js.map +0 -1
- package/dist/src/mocks/duplex.d.ts +0 -3
- package/dist/src/mocks/duplex.d.ts.map +0 -1
- package/dist/src/mocks/duplex.js +0 -7
- package/dist/src/mocks/duplex.js.map +0 -1
- package/dist/src/mocks/index.d.ts +0 -10
- package/dist/src/mocks/index.d.ts.map +0 -1
- package/dist/src/mocks/index.js +0 -9
- package/dist/src/mocks/index.js.map +0 -1
- package/dist/src/mocks/multiaddr-connection.d.ts +0 -17
- package/dist/src/mocks/multiaddr-connection.d.ts.map +0 -1
- package/dist/src/mocks/multiaddr-connection.js +0 -51
- package/dist/src/mocks/multiaddr-connection.js.map +0 -1
- package/dist/src/mocks/muxer.d.ts +0 -9
- package/dist/src/mocks/muxer.d.ts.map +0 -1
- package/dist/src/mocks/muxer.js +0 -277
- package/dist/src/mocks/muxer.js.map +0 -1
- package/dist/src/mocks/registrar.d.ts +0 -18
- package/dist/src/mocks/registrar.d.ts.map +0 -1
- package/dist/src/mocks/registrar.js +0 -73
- package/dist/src/mocks/registrar.js.map +0 -1
- package/dist/src/mocks/upgrader.d.ts +0 -15
- package/dist/src/mocks/upgrader.d.ts.map +0 -1
- package/dist/src/mocks/upgrader.js +0 -33
- package/dist/src/mocks/upgrader.js.map +0 -1
- package/dist/src/peer-discovery/index.d.ts +0 -6
- package/dist/src/peer-discovery/index.d.ts.map +0 -1
- package/dist/src/peer-discovery/index.js +0 -64
- package/dist/src/peer-discovery/index.js.map +0 -1
- package/dist/src/pubsub/api.d.ts +0 -6
- package/dist/src/pubsub/api.d.ts.map +0 -1
- package/dist/src/pubsub/api.js +0 -87
- package/dist/src/pubsub/api.js.map +0 -1
- package/dist/src/pubsub/connection-handlers.d.ts +0 -6
- package/dist/src/pubsub/connection-handlers.d.ts.map +0 -1
- package/dist/src/pubsub/connection-handlers.js +0 -329
- package/dist/src/pubsub/connection-handlers.js.map +0 -1
- package/dist/src/pubsub/emit-self.d.ts +0 -6
- package/dist/src/pubsub/emit-self.d.ts.map +0 -1
- package/dist/src/pubsub/emit-self.js +0 -86
- package/dist/src/pubsub/emit-self.js.map +0 -1
- package/dist/src/pubsub/index.d.ts +0 -10
- package/dist/src/pubsub/index.d.ts.map +0 -1
- package/dist/src/pubsub/index.js +0 -17
- package/dist/src/pubsub/index.js.map +0 -1
- package/dist/src/pubsub/messages.d.ts +0 -6
- package/dist/src/pubsub/messages.d.ts.map +0 -1
- package/dist/src/pubsub/messages.js +0 -46
- package/dist/src/pubsub/messages.js.map +0 -1
- package/dist/src/pubsub/multiple-nodes.d.ts +0 -6
- package/dist/src/pubsub/multiple-nodes.d.ts.map +0 -1
- package/dist/src/pubsub/multiple-nodes.js +0 -350
- package/dist/src/pubsub/multiple-nodes.js.map +0 -1
- package/dist/src/pubsub/two-nodes.d.ts +0 -6
- package/dist/src/pubsub/two-nodes.d.ts.map +0 -1
- package/dist/src/pubsub/two-nodes.js +0 -185
- package/dist/src/pubsub/two-nodes.js.map +0 -1
- package/dist/src/pubsub/utils.d.ts +0 -6
- package/dist/src/pubsub/utils.d.ts.map +0 -1
- package/dist/src/pubsub/utils.js +0 -22
- package/dist/src/pubsub/utils.js.map +0 -1
- package/dist/src/record/index.d.ts +0 -5
- package/dist/src/record/index.d.ts.map +0 -1
- package/dist/src/record/index.js +0 -25
- package/dist/src/record/index.js.map +0 -1
- package/dist/src/stream-muxer/base-test.d.ts +0 -5
- package/dist/src/stream-muxer/base-test.d.ts.map +0 -1
- package/dist/src/stream-muxer/base-test.js +0 -147
- package/dist/src/stream-muxer/base-test.js.map +0 -1
- package/dist/src/stream-muxer/close-test.d.ts +0 -5
- package/dist/src/stream-muxer/close-test.d.ts.map +0 -1
- package/dist/src/stream-muxer/close-test.js +0 -180
- package/dist/src/stream-muxer/close-test.js.map +0 -1
- package/dist/src/stream-muxer/index.d.ts +0 -5
- package/dist/src/stream-muxer/index.d.ts.map +0 -1
- package/dist/src/stream-muxer/index.js +0 -13
- package/dist/src/stream-muxer/index.js.map +0 -1
- package/dist/src/stream-muxer/mega-stress-test.d.ts +0 -5
- package/dist/src/stream-muxer/mega-stress-test.d.ts.map +0 -1
- package/dist/src/stream-muxer/mega-stress-test.js +0 -12
- package/dist/src/stream-muxer/mega-stress-test.js.map +0 -1
- package/dist/src/stream-muxer/spawner.d.ts +0 -4
- package/dist/src/stream-muxer/spawner.d.ts.map +0 -1
- package/dist/src/stream-muxer/spawner.js +0 -32
- package/dist/src/stream-muxer/spawner.js.map +0 -1
- package/dist/src/stream-muxer/stress-test.d.ts +0 -5
- package/dist/src/stream-muxer/stress-test.d.ts.map +0 -1
- package/dist/src/stream-muxer/stress-test.js +0 -26
- package/dist/src/stream-muxer/stress-test.js.map +0 -1
- package/dist/src/topology/topology.d.ts +0 -5
- package/dist/src/topology/topology.d.ts.map +0 -1
- package/dist/src/topology/topology.js +0 -20
- package/dist/src/topology/topology.js.map +0 -1
- package/dist/src/transport/dial-test.d.ts +0 -5
- package/dist/src/transport/dial-test.d.ts.map +0 -1
- package/dist/src/transport/dial-test.js +0 -97
- package/dist/src/transport/dial-test.js.map +0 -1
- package/dist/src/transport/filter-test.d.ts +0 -5
- package/dist/src/transport/filter-test.d.ts.map +0 -1
- package/dist/src/transport/filter-test.js +0 -18
- package/dist/src/transport/filter-test.js.map +0 -1
- package/dist/src/transport/index.d.ts +0 -15
- package/dist/src/transport/index.d.ts.map +0 -1
- package/dist/src/transport/index.js +0 -11
- package/dist/src/transport/index.js.map +0 -1
- package/dist/src/transport/listen-test.d.ts +0 -5
- package/dist/src/transport/listen-test.d.ts.map +0 -1
- package/dist/src/transport/listen-test.js +0 -152
- package/dist/src/transport/listen-test.js.map +0 -1
- package/dist/src/utils/is-valid-tick.d.ts.map +0 -1
- package/dist/src/utils/is-valid-tick.js.map +0 -1
- package/dist/src/utils/peers.d.ts.map +0 -1
- package/dist/src/utils/peers.js.map +0 -1
- package/src/connection/README.md +0 -256
- package/src/connection/connection.ts +0 -176
- package/src/connection/index.ts +0 -7
- package/src/connection-encrypter/index.ts +0 -104
- package/src/connection-encrypter/utils/index.ts +0 -23
- package/src/mocks/connection-encrypter.ts +0 -110
- package/src/mocks/connection-gater.ts +0 -14
- package/src/mocks/connection-manager.ts +0 -141
- package/src/mocks/connection.ts +0 -204
- package/src/mocks/duplex.ts +0 -8
- package/src/mocks/index.ts +0 -10
- package/src/mocks/multiaddr-connection.ts +0 -66
- package/src/mocks/muxer.ts +0 -393
- package/src/mocks/registrar.ts +0 -96
- package/src/mocks/upgrader.ts +0 -46
- package/src/peer-discovery/index.ts +0 -89
- package/src/pubsub/api.ts +0 -115
- package/src/pubsub/connection-handlers.ts +0 -413
- package/src/pubsub/emit-self.ts +0 -105
- package/src/pubsub/index.ts +0 -25
- package/src/pubsub/messages.ts +0 -58
- package/src/pubsub/multiple-nodes.ts +0 -429
- package/src/pubsub/two-nodes.ts +0 -235
- package/src/pubsub/utils.ts +0 -28
- package/src/record/index.ts +0 -32
- package/src/stream-muxer/base-test.ts +0 -190
- package/src/stream-muxer/close-test.ts +0 -227
- package/src/stream-muxer/index.ts +0 -15
- package/src/stream-muxer/mega-stress-test.ts +0 -15
- package/src/stream-muxer/spawner.ts +0 -50
- package/src/stream-muxer/stress-test.ts +0 -29
- package/src/topology/topology.ts +0 -25
- package/src/transport/dial-test.ts +0 -123
- package/src/transport/filter-test.ts +0 -25
- package/src/transport/index.ts +0 -25
- package/src/transport/listen-test.ts +0 -191
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { expect } from 'aegir/chai';
|
|
2
|
-
import { isValidTick } from '../utils/is-valid-tick.js';
|
|
3
|
-
import { mockUpgrader } from '../mocks/upgrader.js';
|
|
4
|
-
import { mockRegistrar } from '../mocks/registrar.js';
|
|
5
|
-
import all from 'it-all';
|
|
6
|
-
import { pipe } from 'it-pipe';
|
|
7
|
-
import { AbortError } from '@libp2p/interfaces/errors';
|
|
8
|
-
import sinon from 'sinon';
|
|
9
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
10
|
-
import drain from 'it-drain';
|
|
11
|
-
export default (common) => {
|
|
12
|
-
describe('dial', () => {
|
|
13
|
-
let upgrader;
|
|
14
|
-
let registrar;
|
|
15
|
-
let addrs;
|
|
16
|
-
let transport;
|
|
17
|
-
let connector;
|
|
18
|
-
let listener;
|
|
19
|
-
before(async () => {
|
|
20
|
-
registrar = mockRegistrar();
|
|
21
|
-
upgrader = mockUpgrader({
|
|
22
|
-
registrar
|
|
23
|
-
});
|
|
24
|
-
({ addrs, transport, connector } = await common.setup());
|
|
25
|
-
});
|
|
26
|
-
after(async () => {
|
|
27
|
-
await common.teardown();
|
|
28
|
-
});
|
|
29
|
-
beforeEach(async () => {
|
|
30
|
-
listener = transport.createListener({
|
|
31
|
-
upgrader
|
|
32
|
-
});
|
|
33
|
-
return await listener.listen(addrs[0]);
|
|
34
|
-
});
|
|
35
|
-
afterEach(async () => {
|
|
36
|
-
sinon.restore();
|
|
37
|
-
connector.restore();
|
|
38
|
-
return await listener.close();
|
|
39
|
-
});
|
|
40
|
-
it('simple', async () => {
|
|
41
|
-
const protocol = '/hello/1.0.0';
|
|
42
|
-
void registrar.handle(protocol, (data) => {
|
|
43
|
-
void pipe([
|
|
44
|
-
uint8ArrayFromString('hey')
|
|
45
|
-
], data.stream, drain);
|
|
46
|
-
});
|
|
47
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
48
|
-
const conn = await transport.dial(addrs[0], {
|
|
49
|
-
upgrader
|
|
50
|
-
});
|
|
51
|
-
const { stream } = await conn.newStream([protocol]);
|
|
52
|
-
const result = await all(stream.source);
|
|
53
|
-
expect(upgradeSpy.callCount).to.equal(1);
|
|
54
|
-
await expect(upgradeSpy.getCall(0).returnValue).to.eventually.equal(conn);
|
|
55
|
-
expect(result.length).to.equal(1);
|
|
56
|
-
expect(result[0]).to.equalBytes(uint8ArrayFromString('hey'));
|
|
57
|
-
await conn.close();
|
|
58
|
-
});
|
|
59
|
-
it('can close connections', async () => {
|
|
60
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
61
|
-
const conn = await transport.dial(addrs[0], {
|
|
62
|
-
upgrader
|
|
63
|
-
});
|
|
64
|
-
expect(upgradeSpy.callCount).to.equal(1);
|
|
65
|
-
await expect(upgradeSpy.getCall(0).returnValue).to.eventually.equal(conn);
|
|
66
|
-
await conn.close();
|
|
67
|
-
expect(isValidTick(conn.stat.timeline.close)).to.equal(true);
|
|
68
|
-
});
|
|
69
|
-
it('to non existent listener', async () => {
|
|
70
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
71
|
-
await expect(transport.dial(addrs[1], {
|
|
72
|
-
upgrader
|
|
73
|
-
})).to.eventually.be.rejected();
|
|
74
|
-
expect(upgradeSpy.callCount).to.equal(0);
|
|
75
|
-
});
|
|
76
|
-
it('abort before dialing throws AbortError', async () => {
|
|
77
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
78
|
-
const controller = new AbortController();
|
|
79
|
-
controller.abort();
|
|
80
|
-
const conn = transport.dial(addrs[0], { signal: controller.signal, upgrader });
|
|
81
|
-
await expect(conn).to.eventually.be.rejected().with.property('code', AbortError.code);
|
|
82
|
-
expect(upgradeSpy.callCount).to.equal(0);
|
|
83
|
-
});
|
|
84
|
-
it('abort while dialing throws AbortError', async () => {
|
|
85
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
86
|
-
// Add a delay to connect() so that we can abort while the dial is in
|
|
87
|
-
// progress
|
|
88
|
-
connector.delay(100);
|
|
89
|
-
const controller = new AbortController();
|
|
90
|
-
const conn = transport.dial(addrs[0], { signal: controller.signal, upgrader });
|
|
91
|
-
setTimeout(() => controller.abort(), 50);
|
|
92
|
-
await expect(conn).to.eventually.be.rejected().with.property('code', AbortError.code);
|
|
93
|
-
expect(upgradeSpy.callCount).to.equal(0);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=dial-test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dial-test.js","sourceRoot":"","sources":["../../../src/transport/dial-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,MAAM,UAAU,CAAA;AAO5B,eAAe,CAAC,MAAwC,EAAE,EAAE;IAC1D,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;QACpB,IAAI,QAAkB,CAAA;QACtB,IAAI,SAAoB,CAAA;QACxB,IAAI,KAAkB,CAAA;QACtB,IAAI,SAAoB,CAAA;QACxB,IAAI,SAAoB,CAAA;QACxB,IAAI,QAAkB,CAAA;QAEtB,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB,SAAS,GAAG,aAAa,EAAE,CAAA;YAC3B,QAAQ,GAAG,YAAY,CAAC;gBACtB,SAAS;aACV,CAAC,CAA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;YACX,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAEpB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;YACxC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;YAC9E,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,EAAE,CAAC,CAAA;YAExC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,CAAA;YACrF,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAC1C,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter-test.d.ts","sourceRoot":"","sources":["../../../src/transport/filter-test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;iCAG/B,UAAU,qBAAqB,CAAC;AAAxD,wBAkBC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { expect } from 'aegir/chai';
|
|
2
|
-
export default (common) => {
|
|
3
|
-
describe('filter', () => {
|
|
4
|
-
let addrs;
|
|
5
|
-
let transport;
|
|
6
|
-
before(async () => {
|
|
7
|
-
({ addrs, transport } = await common.setup());
|
|
8
|
-
});
|
|
9
|
-
after(async () => {
|
|
10
|
-
await common.teardown();
|
|
11
|
-
});
|
|
12
|
-
it('filters addresses', () => {
|
|
13
|
-
const filteredAddrs = transport.filter(addrs);
|
|
14
|
-
expect(filteredAddrs).to.eql(addrs);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=filter-test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter-test.js","sourceRoot":"","sources":["../../../src/transport/filter-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAMnC,eAAe,CAAC,MAAwC,EAAE,EAAE;IAC1D,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtB,IAAI,KAAkB,CAAA;QACtB,IAAI,SAAoB,CAAA;QAExB,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;QAC/C,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAA;QACzB,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAC3B,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAC7C,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { TestSetup } from '../index.js';
|
|
2
|
-
import type { Transport } from '@libp2p/interfaces/transport';
|
|
3
|
-
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
4
|
-
export interface Connector {
|
|
5
|
-
delay: (ms: number) => void;
|
|
6
|
-
restore: () => void;
|
|
7
|
-
}
|
|
8
|
-
export interface TransportTestFixtures {
|
|
9
|
-
addrs: Multiaddr[];
|
|
10
|
-
transport: Transport;
|
|
11
|
-
connector: Connector;
|
|
12
|
-
}
|
|
13
|
-
declare const _default: (common: TestSetup<TransportTestFixtures>) => void;
|
|
14
|
-
export default _default;
|
|
15
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transport/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,SAAS,EAAE,SAAS,CAAA;IACpB,SAAS,EAAE,SAAS,CAAA;CACrB;iCAEuB,UAAU,qBAAqB,CAAC;AAAxD,wBAMC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import dial from './dial-test.js';
|
|
2
|
-
import listen from './listen-test.js';
|
|
3
|
-
import filter from './filter-test.js';
|
|
4
|
-
export default (common) => {
|
|
5
|
-
describe('interface-transport', () => {
|
|
6
|
-
dial(common);
|
|
7
|
-
listen(common);
|
|
8
|
-
filter(common);
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,gBAAgB,CAAA;AACjC,OAAO,MAAM,MAAM,kBAAkB,CAAA;AACrC,OAAO,MAAM,MAAM,kBAAkB,CAAA;AAgBrC,eAAe,CAAC,MAAwC,EAAE,EAAE;IAC1D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;QACnC,IAAI,CAAC,MAAM,CAAC,CAAA;QACZ,MAAM,CAAC,MAAM,CAAC,CAAA;QACd,MAAM,CAAC,MAAM,CAAC,CAAA;IAChB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listen-test.d.ts","sourceRoot":"","sources":["../../../src/transport/listen-test.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;iCAK/B,UAAU,qBAAqB,CAAC;AAAxD,wBA2KC"}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/* eslint max-nested-callbacks: ["error", 8] */
|
|
2
|
-
import { expect } from 'aegir/chai';
|
|
3
|
-
import sinon from 'sinon';
|
|
4
|
-
import pWaitFor from 'p-wait-for';
|
|
5
|
-
import { pipe } from 'it-pipe';
|
|
6
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
7
|
-
import { isValidTick } from '../utils/is-valid-tick.js';
|
|
8
|
-
import { mockUpgrader } from '../mocks/upgrader.js';
|
|
9
|
-
import defer from 'p-defer';
|
|
10
|
-
import { mockRegistrar } from '../mocks/registrar.js';
|
|
11
|
-
import drain from 'it-drain';
|
|
12
|
-
import { CustomEvent } from '@libp2p/interfaces/events';
|
|
13
|
-
export default (common) => {
|
|
14
|
-
describe('listen', () => {
|
|
15
|
-
let upgrader;
|
|
16
|
-
let addrs;
|
|
17
|
-
let transport;
|
|
18
|
-
let registrar;
|
|
19
|
-
before(async () => {
|
|
20
|
-
registrar = mockRegistrar();
|
|
21
|
-
upgrader = mockUpgrader({
|
|
22
|
-
registrar
|
|
23
|
-
});
|
|
24
|
-
({ transport, addrs } = await common.setup());
|
|
25
|
-
});
|
|
26
|
-
after(async () => {
|
|
27
|
-
await common.teardown();
|
|
28
|
-
});
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
sinon.restore();
|
|
31
|
-
});
|
|
32
|
-
it('simple', async () => {
|
|
33
|
-
const listener = transport.createListener({
|
|
34
|
-
upgrader
|
|
35
|
-
});
|
|
36
|
-
await listener.listen(addrs[0]);
|
|
37
|
-
await listener.close();
|
|
38
|
-
});
|
|
39
|
-
it('close listener with connections, through timeout', async () => {
|
|
40
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound');
|
|
41
|
-
const listenerConns = [];
|
|
42
|
-
const protocol = '/test/protocol';
|
|
43
|
-
void registrar.handle(protocol, (data) => {
|
|
44
|
-
void drain(data.stream.source);
|
|
45
|
-
});
|
|
46
|
-
const listener = transport.createListener({
|
|
47
|
-
upgrader,
|
|
48
|
-
handler: (conn) => {
|
|
49
|
-
listenerConns.push(conn);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
// Listen
|
|
53
|
-
await listener.listen(addrs[0]);
|
|
54
|
-
// Create two connections to the listener
|
|
55
|
-
const [conn1] = await Promise.all([
|
|
56
|
-
transport.dial(addrs[0], {
|
|
57
|
-
upgrader
|
|
58
|
-
}),
|
|
59
|
-
transport.dial(addrs[0], {
|
|
60
|
-
upgrader
|
|
61
|
-
})
|
|
62
|
-
]);
|
|
63
|
-
// Give the listener a chance to finish its upgrade
|
|
64
|
-
await pWaitFor(() => listenerConns.length === 2);
|
|
65
|
-
const { stream: stream1 } = await conn1.newStream([protocol]);
|
|
66
|
-
// Wait for the data send and close to finish
|
|
67
|
-
await Promise.all([
|
|
68
|
-
pipe([uint8ArrayFromString('Some data that is never handled')], stream1),
|
|
69
|
-
// Closer the listener (will take a couple of seconds to time out)
|
|
70
|
-
listener.close()
|
|
71
|
-
]);
|
|
72
|
-
await stream1.close();
|
|
73
|
-
await conn1.close();
|
|
74
|
-
expect(isValidTick(conn1.stat.timeline.close)).to.equal(true);
|
|
75
|
-
listenerConns.forEach(conn => {
|
|
76
|
-
expect(isValidTick(conn.stat.timeline.close)).to.equal(true);
|
|
77
|
-
});
|
|
78
|
-
// 2 dials = 2 connections upgraded
|
|
79
|
-
expect(upgradeSpy.callCount).to.equal(2);
|
|
80
|
-
});
|
|
81
|
-
it('should not handle connection if upgradeInbound throws', async () => {
|
|
82
|
-
sinon.stub(upgrader, 'upgradeInbound').throws();
|
|
83
|
-
const listener = transport.createListener({
|
|
84
|
-
upgrader
|
|
85
|
-
});
|
|
86
|
-
// Listen
|
|
87
|
-
await listener.listen(addrs[0]);
|
|
88
|
-
// Create a connection to the listener
|
|
89
|
-
const conn = await transport.dial(addrs[0], {
|
|
90
|
-
upgrader
|
|
91
|
-
});
|
|
92
|
-
await pWaitFor(() => typeof conn.stat.timeline.close === 'number');
|
|
93
|
-
await listener.close();
|
|
94
|
-
});
|
|
95
|
-
describe('events', () => {
|
|
96
|
-
it('connection', async () => {
|
|
97
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound');
|
|
98
|
-
const listener = transport.createListener({
|
|
99
|
-
upgrader
|
|
100
|
-
});
|
|
101
|
-
const deferred = defer();
|
|
102
|
-
let conn;
|
|
103
|
-
listener.addEventListener('connection', (evt) => {
|
|
104
|
-
conn = evt.detail;
|
|
105
|
-
deferred.resolve();
|
|
106
|
-
});
|
|
107
|
-
void (async () => {
|
|
108
|
-
await listener.listen(addrs[0]);
|
|
109
|
-
await transport.dial(addrs[0], {
|
|
110
|
-
upgrader
|
|
111
|
-
});
|
|
112
|
-
})();
|
|
113
|
-
await deferred.promise;
|
|
114
|
-
await expect(upgradeSpy.getCall(0).returnValue).to.eventually.equal(conn);
|
|
115
|
-
expect(upgradeSpy.callCount).to.equal(1);
|
|
116
|
-
await listener.close();
|
|
117
|
-
});
|
|
118
|
-
it('listening', (done) => {
|
|
119
|
-
const listener = transport.createListener({
|
|
120
|
-
upgrader
|
|
121
|
-
});
|
|
122
|
-
listener.addEventListener('listening', () => {
|
|
123
|
-
listener.close().then(done, done);
|
|
124
|
-
});
|
|
125
|
-
void listener.listen(addrs[0]);
|
|
126
|
-
});
|
|
127
|
-
it('error', (done) => {
|
|
128
|
-
const listener = transport.createListener({
|
|
129
|
-
upgrader
|
|
130
|
-
});
|
|
131
|
-
listener.addEventListener('error', (evt) => {
|
|
132
|
-
expect(evt.detail).to.be.an.instanceOf(Error);
|
|
133
|
-
listener.close().then(done, done);
|
|
134
|
-
});
|
|
135
|
-
listener.dispatchEvent(new CustomEvent('error', {
|
|
136
|
-
detail: new Error('my err')
|
|
137
|
-
}));
|
|
138
|
-
});
|
|
139
|
-
it('close', (done) => {
|
|
140
|
-
const listener = transport.createListener({
|
|
141
|
-
upgrader
|
|
142
|
-
});
|
|
143
|
-
listener.addEventListener('close', () => done());
|
|
144
|
-
void (async () => {
|
|
145
|
-
await listener.listen(addrs[0]);
|
|
146
|
-
await listener.close();
|
|
147
|
-
})();
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
//# sourceMappingURL=listen-test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listen-test.js","sourceRoot":"","sources":["../../../src/transport/listen-test.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,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":[],"mappings":"AACA;;;GAGG;AACH,wBAAgB,WAAW,CAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAE,MAAa,WAY5D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-valid-tick.js","sourceRoot":"","sources":["../../../src/utils/is-valid-tick.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAE,IAAa,EAAE,KAAa,IAAI;IAC3D,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACzC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAEtB,IAAI,IAAI,GAAG,GAAG,GAAG,EAAE,IAAI,IAAI,IAAI,GAAG,EAAE;QAClC,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"peers.d.ts","sourceRoot":"","sources":["../../../src/utils/peers.ts"],"names":[],"mappings":";;;;;AAAA,wBAwBE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"peers.js","sourceRoot":"","sources":["../../../src/utils/peers.ts"],"names":[],"mappings":"AAAA,eAAe,CAAC;QACd,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,0jDAA0jD;QACnkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,EAAE;QACD,EAAE,EAAE,gDAAgD;QACpD,OAAO,EAAE,8jDAA8jD;QACvkD,MAAM,EAAE,kZAAkZ;KAC3Z,CAAC,CAAA"}
|
package/src/connection/README.md
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
interface-connection
|
|
2
|
-
==================
|
|
3
|
-
|
|
4
|
-
This is a test suite and interface you can use to implement a connection. The connection interface contains all the metadata associated with it, as well as an array of the streams opened through this connection. In the same way as the connection, a stream contains properties with its metadata, plus an iterable duplex object that offers a mechanism for writing and reading data, with back pressure. This module and test suite were heavily inspired by abstract-blob-store and interface-stream-muxer.
|
|
5
|
-
|
|
6
|
-
The primary goal of this module is to enable developers to pick, swap or upgrade their connection without losing the same API expectations and mechanisms such as back pressure and the ability to half close a connection.
|
|
7
|
-
|
|
8
|
-
Publishing a test suite as a module lets multiple modules ensure compatibility since they use the same test suite.
|
|
9
|
-
|
|
10
|
-
## Usage
|
|
11
|
-
|
|
12
|
-
### Connection
|
|
13
|
-
|
|
14
|
-
Before creating a connection from a transport compatible with `libp2p` it is important to understand some concepts:
|
|
15
|
-
|
|
16
|
-
- **socket**: the underlying raw duplex connection between two nodes. It is created by the transports during a dial/listen.
|
|
17
|
-
- **[multiaddr connection](https://github.com/libp2p/interface-transport#multiaddrconnection)**: an abstraction over the socket to allow it to work with multiaddr addresses. It is a duplex connection that transports create to wrap the socket before passing to an upgrader that turns it into a standard connection (see below).
|
|
18
|
-
- **connection**: a connection between two _peers_ that has built in multiplexing and info about the connected peer. It is created from a [multiaddr connection](https://github.com/libp2p/interface-transport#multiaddrconnection) by an upgrader. The upgrader uses multistream-select to add secio and multiplexing and returns this object.
|
|
19
|
-
- **stream**: a muxed duplex channel of the `connection`. Each connection may have many streams.
|
|
20
|
-
|
|
21
|
-
A connection stands for the libp2p communication duplex layer between two nodes. It is **not** the underlying raw transport duplex layer (socket), such as a TCP socket, but an abstracted layer that sits on top of the raw socket.
|
|
22
|
-
|
|
23
|
-
This helps ensuring that the transport is responsible for socket management, while also allowing the application layer to handle the connection management.
|
|
24
|
-
|
|
25
|
-
### Test suite
|
|
26
|
-
|
|
27
|
-
```js
|
|
28
|
-
const tests = require('libp2p-interfaces-compliance-tests/connection')
|
|
29
|
-
describe('your connection', () => {
|
|
30
|
-
tests({
|
|
31
|
-
// Options should be passed to your connection
|
|
32
|
-
async setup (options) {
|
|
33
|
-
return YourConnection
|
|
34
|
-
},
|
|
35
|
-
async teardown () {
|
|
36
|
-
// cleanup resources created by setup()
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## API
|
|
43
|
-
|
|
44
|
-
### Connection
|
|
45
|
-
|
|
46
|
-
A valid connection (one that follows this abstraction), must implement the following API:
|
|
47
|
-
|
|
48
|
-
- type: `Connection`
|
|
49
|
-
```js
|
|
50
|
-
new Connection({
|
|
51
|
-
localAddr,
|
|
52
|
-
remoteAddr,
|
|
53
|
-
localPeer,
|
|
54
|
-
remotePeer,
|
|
55
|
-
newStream,
|
|
56
|
-
close,
|
|
57
|
-
getStreams,
|
|
58
|
-
stat: {
|
|
59
|
-
direction,
|
|
60
|
-
timeline: {
|
|
61
|
-
open,
|
|
62
|
-
upgraded
|
|
63
|
-
},
|
|
64
|
-
multiplexer,
|
|
65
|
-
encryption
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
```
|
|
69
|
-
- `<Multiaddr> conn.localAddr`
|
|
70
|
-
- `<Multiaddr> conn.remoteAddr`
|
|
71
|
-
- `<PeerId> conn.localPeer`
|
|
72
|
-
- `<PeerId> conn.remotePeer`
|
|
73
|
-
- `<Object> conn.stat`
|
|
74
|
-
- `<Map> conn.registry`
|
|
75
|
-
- `Array<Stream> conn.streams`
|
|
76
|
-
- `Promise<object> conn.newStream(Array<protocols>)`
|
|
77
|
-
- `<void> conn.removeStream(id)`
|
|
78
|
-
- `<Stream> conn.addStream(stream, protocol, metadata)`
|
|
79
|
-
- `Promise<> conn.close()`
|
|
80
|
-
|
|
81
|
-
It can be obtained as follows:
|
|
82
|
-
|
|
83
|
-
```js
|
|
84
|
-
const { Connection } = require('interface-connection')
|
|
85
|
-
|
|
86
|
-
const conn = new Connection({
|
|
87
|
-
localAddr: maConn.localAddr,
|
|
88
|
-
remoteAddr: maConn.remoteAddr,
|
|
89
|
-
localPeer: this._peerId,
|
|
90
|
-
remotePeer,
|
|
91
|
-
newStream,
|
|
92
|
-
close: err => maConn.close(err),
|
|
93
|
-
getStreams,
|
|
94
|
-
stats: {
|
|
95
|
-
direction: 'outbound',
|
|
96
|
-
timeline: {
|
|
97
|
-
open: maConn.timeline.open,
|
|
98
|
-
upgraded: Date.now()
|
|
99
|
-
},
|
|
100
|
-
multiplexer,
|
|
101
|
-
encryption
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
#### Creating a connection instance
|
|
107
|
-
|
|
108
|
-
- `JavaScript` - `const conn = new Connection({localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, direction, multiplexer, encryption})`
|
|
109
|
-
|
|
110
|
-
Creates a new Connection instance.
|
|
111
|
-
|
|
112
|
-
`localAddr` is the optional [multiaddr](https://github.com/multiformats/multiaddr) address used by the local peer to reach the remote.
|
|
113
|
-
`remoteAddr` is the optional [multiaddr](https://github.com/multiformats/multiaddr) address used to communicate with the remote peer.
|
|
114
|
-
`localPeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the local peer.
|
|
115
|
-
`remotePeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the remote peer.
|
|
116
|
-
`newStream` is the `function` responsible for getting a new muxed+multistream-selected stream.
|
|
117
|
-
`close` is the `function` responsible for closing the raw connection.
|
|
118
|
-
`getStreams` is the `function` responsible for getting the streams muxed within the connection.
|
|
119
|
-
`stats` is an `object` with the metadata of the connection. It contains:
|
|
120
|
-
- `direction` is a `string` indicating whether the connection is `inbound` or `outbound`.
|
|
121
|
-
- `timeline` is an `object` with the relevant events timestamps of the connection (`open`, `upgraded` and `closed`; the `closed` will be added when the connection is closed).
|
|
122
|
-
- `multiplexer` is a `string` with the connection multiplexing codec (optional).
|
|
123
|
-
- `encryption` is a `string` with the connection encryption method identifier (optional).
|
|
124
|
-
- `status` is a `string` indicating the overall status of the connection. It is one of [`'open'`, `'closing'`, `'closed'`]
|
|
125
|
-
|
|
126
|
-
#### Create a new stream
|
|
127
|
-
|
|
128
|
-
- `JavaScript` - `conn.newStream(protocols)`
|
|
129
|
-
|
|
130
|
-
Create a new stream within the connection.
|
|
131
|
-
|
|
132
|
-
`protocols` is an array of the intended protocol to use (by order of preference). Example: `[/echo/1.0.0]`
|
|
133
|
-
|
|
134
|
-
It returns a `Promise` with an object with the following properties:
|
|
135
|
-
|
|
136
|
-
```js
|
|
137
|
-
{
|
|
138
|
-
stream,
|
|
139
|
-
protocol
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
The stream property contains the muxed stream, while the protocol contains the protocol codec used by the stream.
|
|
144
|
-
|
|
145
|
-
#### Add stream metadata
|
|
146
|
-
|
|
147
|
-
- `JavaScript` - `conn.addStream(stream, { protocol, ...metadata })`
|
|
148
|
-
|
|
149
|
-
Add a new stream to the connection registry.
|
|
150
|
-
|
|
151
|
-
`stream` is a muxed stream.
|
|
152
|
-
`protocol` is the string codec for the protocol used by the stream. Example: `/echo/1.0.0`
|
|
153
|
-
`metadata` is an object containing any additional, optional, stream metadata that you wish to track (such as its `tags`).
|
|
154
|
-
|
|
155
|
-
#### Remove a from the registry
|
|
156
|
-
|
|
157
|
-
- `JavaScript` - `conn.removeStream(id)`
|
|
158
|
-
|
|
159
|
-
Removes the stream with the given id from the connection registry.
|
|
160
|
-
|
|
161
|
-
`id` is the unique id of the stream for this connection.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
#### Close connection
|
|
165
|
-
|
|
166
|
-
- `JavaScript` - `conn.close()`
|
|
167
|
-
|
|
168
|
-
This method closes the connection to the remote peer, as well as all the streams muxed within the connection.
|
|
169
|
-
|
|
170
|
-
It returns a `Promise`.
|
|
171
|
-
|
|
172
|
-
#### Connection identifier
|
|
173
|
-
|
|
174
|
-
- `JavaScript` - `conn.id`
|
|
175
|
-
|
|
176
|
-
This property contains the identifier of the connection.
|
|
177
|
-
|
|
178
|
-
#### Connection streams registry
|
|
179
|
-
|
|
180
|
-
- `JavaScript` - `conn.registry`
|
|
181
|
-
|
|
182
|
-
This property contains a map with the muxed streams indexed by their id. This registry contains the protocol used by the stream, as well as its metadata.
|
|
183
|
-
|
|
184
|
-
#### Remote peer
|
|
185
|
-
|
|
186
|
-
- `JavaScript` - `conn.remotePeer`
|
|
187
|
-
|
|
188
|
-
This property contains the remote `peer-id` of this connection.
|
|
189
|
-
|
|
190
|
-
#### Local peer
|
|
191
|
-
|
|
192
|
-
- `JavaScript` - `conn.localPeer`
|
|
193
|
-
|
|
194
|
-
This property contains the local `peer-id` of this connection.
|
|
195
|
-
|
|
196
|
-
#### Get the connection Streams
|
|
197
|
-
|
|
198
|
-
- `JavaScript` - `conn.streams`
|
|
199
|
-
|
|
200
|
-
This getter returns all the muxed streams within the connection.
|
|
201
|
-
|
|
202
|
-
It returns an `Array`.
|
|
203
|
-
|
|
204
|
-
#### Remote address
|
|
205
|
-
|
|
206
|
-
- `JavaScript` - `conn.remoteAddr`
|
|
207
|
-
|
|
208
|
-
This getter returns the `remote` [multiaddr](https://github.com/multiformats/multiaddr) address.
|
|
209
|
-
|
|
210
|
-
#### Local address
|
|
211
|
-
|
|
212
|
-
- `JavaScript` - `conn.localAddr`
|
|
213
|
-
|
|
214
|
-
This getter returns the `local` [multiaddr](https://github.com/multiformats/multiaddr) address.
|
|
215
|
-
|
|
216
|
-
#### Stat
|
|
217
|
-
|
|
218
|
-
- `JavaScript` - `conn.stat`
|
|
219
|
-
|
|
220
|
-
This getter returns an `Object` with the metadata of the connection, as follows:
|
|
221
|
-
|
|
222
|
-
- `status`:
|
|
223
|
-
|
|
224
|
-
This property contains the status of the connection. It can be either `open`, `closing` or `closed`. Once the connection is created it is in an `open` status. When a `conn.close()` happens, the status will change to `closing` and finally, after all the connection streams are properly closed, the status will be `closed`. These values can also be directly referenced by importing the `status` file:
|
|
225
|
-
|
|
226
|
-
```js
|
|
227
|
-
const {
|
|
228
|
-
OPEN, CLOSING, CLOSED
|
|
229
|
-
} = require('libp2p-interfaces/src/connection/status')
|
|
230
|
-
|
|
231
|
-
if (connection.stat.status === OPEN) {
|
|
232
|
-
// ...
|
|
233
|
-
}
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
- `timeline`:
|
|
237
|
-
|
|
238
|
-
This property contains an object with the `open`, `upgraded` and `close` timestamps of the connection. Note that, the `close` timestamp is `undefined` until the connection is closed.
|
|
239
|
-
|
|
240
|
-
- `direction`:
|
|
241
|
-
|
|
242
|
-
This property contains the direction of the peer in the connection. It can be `inbound` or `outbound`.
|
|
243
|
-
|
|
244
|
-
- `multiplexer`:
|
|
245
|
-
|
|
246
|
-
This property contains the `multiplexing` codec being used in the connection.
|
|
247
|
-
|
|
248
|
-
- `encryption`:
|
|
249
|
-
|
|
250
|
-
This property contains the encryption method being used in the connection. It is `undefined` if the connection is not encrypted.
|
|
251
|
-
|
|
252
|
-
#### Tags
|
|
253
|
-
|
|
254
|
-
- `JavaScript` - `conn.tags`
|
|
255
|
-
|
|
256
|
-
This property contains an array of tags associated with the connection. New tags can be pushed to this array during the connection's lifetime.
|