@libp2p/interface-compliance-tests 6.1.8 → 6.1.9
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/dist/src/matchers.d.ts +6 -0
- package/dist/src/matchers.d.ts.map +1 -1
- package/dist/src/matchers.js +6 -0
- package/dist/src/matchers.js.map +1 -1
- package/dist/src/mocks/index.d.ts +0 -2
- package/dist/src/mocks/index.d.ts.map +1 -1
- package/dist/src/mocks/index.js +0 -2
- package/dist/src/mocks/index.js.map +1 -1
- package/dist/src/mocks/muxer.d.ts +8 -3
- package/dist/src/mocks/muxer.d.ts.map +1 -1
- package/dist/src/mocks/muxer.js +15 -6
- package/dist/src/mocks/muxer.js.map +1 -1
- package/dist/src/mocks/upgrader.d.ts.map +1 -1
- package/dist/src/mocks/upgrader.js +0 -1
- package/dist/src/mocks/upgrader.js.map +1 -1
- package/dist/src/transport/index.d.ts +23 -10
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +418 -6
- package/dist/src/transport/index.js.map +1 -1
- package/dist/src/transport/utils.d.ts +17 -0
- package/dist/src/transport/utils.d.ts.map +1 -0
- package/dist/src/transport/utils.js +63 -0
- package/dist/src/transport/utils.js.map +1 -0
- package/dist/typedoc-urls.json +1 -6
- package/package.json +11 -10
- package/src/matchers.ts +6 -0
- package/src/mocks/index.ts +0 -2
- package/src/mocks/muxer.ts +24 -10
- package/src/mocks/upgrader.ts +1 -3
- package/src/transport/index.ts +570 -16
- package/src/transport/utils.ts +76 -0
- 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 -135
- package/dist/src/connection/index.js.map +0 -1
- package/dist/src/mocks/connection-gater.d.ts +0 -3
- package/dist/src/mocks/connection-gater.d.ts.map +0 -1
- package/dist/src/mocks/connection-gater.js +0 -17
- package/dist/src/mocks/connection-gater.js.map +0 -1
- package/dist/src/mocks/metrics.d.ts +0 -3
- package/dist/src/mocks/metrics.d.ts.map +0 -1
- package/dist/src/mocks/metrics.js +0 -286
- package/dist/src/mocks/metrics.js.map +0 -1
- package/dist/src/mocks/peer-discovery.d.ts +0 -21
- package/dist/src/mocks/peer-discovery.d.ts.map +0 -1
- package/dist/src/mocks/peer-discovery.js +0 -47
- package/dist/src/mocks/peer-discovery.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 -99
- 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 -24
- package/dist/src/transport/filter-test.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 -154
- package/dist/src/transport/listen-test.js.map +0 -1
- package/src/connection/index.ts +0 -166
- package/src/mocks/connection-gater.ts +0 -18
- package/src/mocks/metrics.ts +0 -385
- package/src/mocks/peer-discovery.ts +0 -59
- package/src/transport/dial-test.ts +0 -125
- package/src/transport/filter-test.ts +0 -32
- package/src/transport/listen-test.ts +0 -192
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { TypedEventEmitter } from '@libp2p/interface';
|
|
2
|
-
import { expect } from 'aegir/chai';
|
|
3
|
-
import all from 'it-all';
|
|
4
|
-
import drain from 'it-drain';
|
|
5
|
-
import { pipe } from 'it-pipe';
|
|
6
|
-
import sinon from 'sinon';
|
|
7
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
8
|
-
import { isValidTick } from '../is-valid-tick.js';
|
|
9
|
-
import { mockUpgrader, mockRegistrar } from '../mocks/index.js';
|
|
10
|
-
export default (common) => {
|
|
11
|
-
describe('dial', () => {
|
|
12
|
-
let upgrader;
|
|
13
|
-
let registrar;
|
|
14
|
-
let listenAddrs;
|
|
15
|
-
let dialAddrs;
|
|
16
|
-
let dialer;
|
|
17
|
-
let listener;
|
|
18
|
-
let connector;
|
|
19
|
-
let listen;
|
|
20
|
-
before(async () => {
|
|
21
|
-
registrar = mockRegistrar();
|
|
22
|
-
upgrader = mockUpgrader({
|
|
23
|
-
registrar,
|
|
24
|
-
events: new TypedEventEmitter()
|
|
25
|
-
});
|
|
26
|
-
({ listenAddrs, dialAddrs, dialer, listener, connector } = await common.setup());
|
|
27
|
-
});
|
|
28
|
-
after(async () => {
|
|
29
|
-
await common.teardown();
|
|
30
|
-
});
|
|
31
|
-
beforeEach(async () => {
|
|
32
|
-
listen = listener.createListener({
|
|
33
|
-
upgrader
|
|
34
|
-
});
|
|
35
|
-
await listen.listen(listenAddrs[0]);
|
|
36
|
-
});
|
|
37
|
-
afterEach(async () => {
|
|
38
|
-
sinon.restore();
|
|
39
|
-
connector.restore();
|
|
40
|
-
await listen.close();
|
|
41
|
-
});
|
|
42
|
-
it('simple', async () => {
|
|
43
|
-
const protocol = '/hello/1.0.0';
|
|
44
|
-
void registrar.handle(protocol, (data) => {
|
|
45
|
-
void pipe([
|
|
46
|
-
uint8ArrayFromString('hey')
|
|
47
|
-
], data.stream, drain);
|
|
48
|
-
});
|
|
49
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
50
|
-
const conn = await dialer.dial(dialAddrs[0], {
|
|
51
|
-
upgrader
|
|
52
|
-
});
|
|
53
|
-
const stream = await conn.newStream([protocol]);
|
|
54
|
-
const result = await all(stream.source);
|
|
55
|
-
expect(upgradeSpy.callCount).to.equal(1);
|
|
56
|
-
await expect(upgradeSpy.getCall(0).returnValue).to.eventually.equal(conn);
|
|
57
|
-
expect(result.length).to.equal(1);
|
|
58
|
-
expect(result[0].subarray()).to.equalBytes(uint8ArrayFromString('hey'));
|
|
59
|
-
await conn.close();
|
|
60
|
-
});
|
|
61
|
-
it('can close connections', async () => {
|
|
62
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
63
|
-
const conn = await dialer.dial(dialAddrs[0], {
|
|
64
|
-
upgrader
|
|
65
|
-
});
|
|
66
|
-
expect(upgradeSpy.callCount).to.equal(1);
|
|
67
|
-
await expect(upgradeSpy.getCall(0).returnValue).to.eventually.equal(conn);
|
|
68
|
-
await conn.close();
|
|
69
|
-
expect(isValidTick(conn.timeline.close)).to.equal(true);
|
|
70
|
-
});
|
|
71
|
-
it('to non existent listener', async () => {
|
|
72
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
73
|
-
await expect(dialer.dial(dialAddrs[1], {
|
|
74
|
-
upgrader
|
|
75
|
-
})).to.eventually.be.rejected();
|
|
76
|
-
expect(upgradeSpy.callCount).to.equal(0);
|
|
77
|
-
});
|
|
78
|
-
it('abort before dialing throws AbortError', async () => {
|
|
79
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
80
|
-
const controller = new AbortController();
|
|
81
|
-
controller.abort();
|
|
82
|
-
const conn = dialer.dial(dialAddrs[0], { signal: controller.signal, upgrader });
|
|
83
|
-
await expect(conn).to.eventually.be.rejected().with.property('name', 'AbortError');
|
|
84
|
-
expect(upgradeSpy.callCount).to.equal(0);
|
|
85
|
-
});
|
|
86
|
-
it('abort while dialing throws AbortError', async () => {
|
|
87
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound');
|
|
88
|
-
// Add a delay to connect() so that we can abort while the dial is in
|
|
89
|
-
// progress
|
|
90
|
-
connector.delay(100);
|
|
91
|
-
const controller = new AbortController();
|
|
92
|
-
const conn = dialer.dial(dialAddrs[0], { signal: controller.signal, upgrader });
|
|
93
|
-
setTimeout(() => { controller.abort(); }, 50);
|
|
94
|
-
await expect(conn).to.eventually.be.rejected().with.property('name', 'AbortError');
|
|
95
|
-
expect(upgradeSpy.callCount).to.equal(0);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
//# sourceMappingURL=dial-test.js.map
|
|
@@ -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YAC/E,UAAU,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,KAAK,EAAE,CAAA,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YAE5C,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;YAClF,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,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;iCAIpB,UAAU,qBAAqB,CAAC,KAAG,IAAI;AAA/D,wBAyBC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { expect } from 'aegir/chai';
|
|
2
|
-
export default (common) => {
|
|
3
|
-
describe('filter', () => {
|
|
4
|
-
let listenAddrs;
|
|
5
|
-
let dialAddrs;
|
|
6
|
-
let dialer;
|
|
7
|
-
let listener;
|
|
8
|
-
before(async () => {
|
|
9
|
-
({ listenAddrs, dialAddrs, dialer, listener } = await common.setup());
|
|
10
|
-
});
|
|
11
|
-
after(async () => {
|
|
12
|
-
await common.teardown();
|
|
13
|
-
});
|
|
14
|
-
it('filters listen addresses', () => {
|
|
15
|
-
const filteredAddrs = listener.listenFilter(listenAddrs);
|
|
16
|
-
expect(filteredAddrs).to.eql(listenAddrs);
|
|
17
|
-
});
|
|
18
|
-
it('filters dial addresses', () => {
|
|
19
|
-
const filteredAddrs = dialer.dialFilter(dialAddrs);
|
|
20
|
-
expect(filteredAddrs).to.eql(dialAddrs);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
//# 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,EAAQ,EAAE;IAChE,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtB,IAAI,WAAwB,CAAA;QAC5B,IAAI,SAAsB,CAAA;QAC1B,IAAI,MAAiB,CAAA;QACrB,IAAI,QAAmB,CAAA;QAEvB,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;QACvE,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAA;QACzB,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;YAClC,MAAM,aAAa,GAAG,QAAQ,CAAC,YAAY,CAAC,WAAW,CAAC,CAAA;YACxD,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QAC3C,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;YAChC,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;YAClD,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;IACJ,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":"AAWA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;iCAKpB,UAAU,qBAAqB,CAAC,KAAG,IAAI;AAA/D,wBA8KC"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/* eslint max-nested-callbacks: ["error", 8] */
|
|
2
|
-
import { TypedEventEmitter } from '@libp2p/interface';
|
|
3
|
-
import { expect } from 'aegir/chai';
|
|
4
|
-
import drain from 'it-drain';
|
|
5
|
-
import { pipe } from 'it-pipe';
|
|
6
|
-
import defer from 'p-defer';
|
|
7
|
-
import pWaitFor from 'p-wait-for';
|
|
8
|
-
import sinon from 'sinon';
|
|
9
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
10
|
-
import { isValidTick } from '../is-valid-tick.js';
|
|
11
|
-
import { mockUpgrader, mockRegistrar } from '../mocks/index.js';
|
|
12
|
-
export default (common) => {
|
|
13
|
-
describe('listen', () => {
|
|
14
|
-
let upgrader;
|
|
15
|
-
let listenAddrs;
|
|
16
|
-
let dialAddrs;
|
|
17
|
-
let dialer;
|
|
18
|
-
let listener;
|
|
19
|
-
let registrar;
|
|
20
|
-
before(async () => {
|
|
21
|
-
registrar = mockRegistrar();
|
|
22
|
-
upgrader = mockUpgrader({
|
|
23
|
-
registrar,
|
|
24
|
-
events: new TypedEventEmitter()
|
|
25
|
-
});
|
|
26
|
-
({ dialer, listener, listenAddrs, dialAddrs } = await common.setup());
|
|
27
|
-
});
|
|
28
|
-
after(async () => {
|
|
29
|
-
await common.teardown();
|
|
30
|
-
});
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
sinon.restore();
|
|
33
|
-
});
|
|
34
|
-
it('simple', async () => {
|
|
35
|
-
const listen = listener.createListener({
|
|
36
|
-
upgrader
|
|
37
|
-
});
|
|
38
|
-
await listen.listen(listenAddrs[0]);
|
|
39
|
-
await listen.close();
|
|
40
|
-
});
|
|
41
|
-
it('close listener with connections, through timeout', async () => {
|
|
42
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound');
|
|
43
|
-
const listenerConns = [];
|
|
44
|
-
const protocol = '/test/protocol';
|
|
45
|
-
void registrar.handle(protocol, (data) => {
|
|
46
|
-
void drain(data.stream.source);
|
|
47
|
-
});
|
|
48
|
-
const listen = listener.createListener({
|
|
49
|
-
upgrader,
|
|
50
|
-
handler: (conn) => {
|
|
51
|
-
listenerConns.push(conn);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
// Listen
|
|
55
|
-
await listen.listen(listenAddrs[0]);
|
|
56
|
-
// Create two connections to the listener
|
|
57
|
-
const [conn1] = await Promise.all([
|
|
58
|
-
dialer.dial(dialAddrs[0], {
|
|
59
|
-
upgrader
|
|
60
|
-
}),
|
|
61
|
-
dialer.dial(dialAddrs[0], {
|
|
62
|
-
upgrader
|
|
63
|
-
})
|
|
64
|
-
]);
|
|
65
|
-
// Give the listener a chance to finish its upgrade
|
|
66
|
-
await pWaitFor(() => listenerConns.length === 2);
|
|
67
|
-
const stream1 = await conn1.newStream([protocol]);
|
|
68
|
-
// Wait for the data send and close to finish
|
|
69
|
-
await Promise.all([
|
|
70
|
-
pipe([uint8ArrayFromString('Some data that is never handled')], stream1),
|
|
71
|
-
// Closer the listener (will take a couple of seconds to time out)
|
|
72
|
-
listen.close()
|
|
73
|
-
]);
|
|
74
|
-
await stream1.close();
|
|
75
|
-
await conn1.close();
|
|
76
|
-
expect(isValidTick(conn1.timeline.close)).to.equal(true);
|
|
77
|
-
listenerConns.forEach(conn => {
|
|
78
|
-
expect(isValidTick(conn.timeline.close)).to.equal(true);
|
|
79
|
-
});
|
|
80
|
-
// 2 dials = 2 connections upgraded
|
|
81
|
-
expect(upgradeSpy.callCount).to.equal(2);
|
|
82
|
-
});
|
|
83
|
-
it('should not handle connection if upgradeInbound rejects', async () => {
|
|
84
|
-
sinon.stub(upgrader, 'upgradeInbound').rejects();
|
|
85
|
-
const listen = listener.createListener({
|
|
86
|
-
upgrader
|
|
87
|
-
});
|
|
88
|
-
// Listen
|
|
89
|
-
await listen.listen(listenAddrs[0]);
|
|
90
|
-
// Create a connection to the listener
|
|
91
|
-
const conn = await dialer.dial(dialAddrs[0], {
|
|
92
|
-
upgrader
|
|
93
|
-
});
|
|
94
|
-
await pWaitFor(() => typeof conn.timeline.close === 'number');
|
|
95
|
-
await listen.close();
|
|
96
|
-
});
|
|
97
|
-
describe('events', () => {
|
|
98
|
-
it('connection', async () => {
|
|
99
|
-
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound');
|
|
100
|
-
const listen = listener.createListener({
|
|
101
|
-
upgrader
|
|
102
|
-
});
|
|
103
|
-
const deferred = defer();
|
|
104
|
-
let conn;
|
|
105
|
-
listen.addEventListener('connection', (evt) => {
|
|
106
|
-
conn = evt.detail;
|
|
107
|
-
deferred.resolve();
|
|
108
|
-
});
|
|
109
|
-
void (async () => {
|
|
110
|
-
await listen.listen(listenAddrs[0]);
|
|
111
|
-
await dialer.dial(dialAddrs[0], {
|
|
112
|
-
upgrader
|
|
113
|
-
});
|
|
114
|
-
})();
|
|
115
|
-
await deferred.promise;
|
|
116
|
-
await expect(upgradeSpy.getCall(0).returnValue).to.eventually.equal(conn);
|
|
117
|
-
expect(upgradeSpy.callCount).to.equal(1);
|
|
118
|
-
await listen.close();
|
|
119
|
-
});
|
|
120
|
-
it('listening', (done) => {
|
|
121
|
-
const listen = listener.createListener({
|
|
122
|
-
upgrader
|
|
123
|
-
});
|
|
124
|
-
listen.addEventListener('listening', () => {
|
|
125
|
-
listen.close().then(done, done);
|
|
126
|
-
});
|
|
127
|
-
void listen.listen(listenAddrs[0]);
|
|
128
|
-
});
|
|
129
|
-
it('error', (done) => {
|
|
130
|
-
const listen = listener.createListener({
|
|
131
|
-
upgrader
|
|
132
|
-
});
|
|
133
|
-
listen.addEventListener('error', (evt) => {
|
|
134
|
-
expect(evt.detail).to.be.an.instanceOf(Error);
|
|
135
|
-
listen.close().then(done, done);
|
|
136
|
-
});
|
|
137
|
-
listen.dispatchEvent(new CustomEvent('error', {
|
|
138
|
-
detail: new Error('my err')
|
|
139
|
-
}));
|
|
140
|
-
});
|
|
141
|
-
it('close', (done) => {
|
|
142
|
-
const listen = listener.createListener({
|
|
143
|
-
upgrader
|
|
144
|
-
});
|
|
145
|
-
listen.addEventListener('close', () => { done(); });
|
|
146
|
-
void (async () => {
|
|
147
|
-
await listen.listen(listenAddrs[0]);
|
|
148
|
-
await listen.close();
|
|
149
|
-
})();
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
//# 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,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAO/D,eAAe,CAAC,MAAwC,EAAQ,EAAE;IAChE,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtB,IAAI,QAAkB,CAAA;QACtB,IA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T,CAAC,CAAA;gBACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;oBACvC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;oBAC7C,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;gBACjC,CAAC,CAAC,CAAA;gBACF,MAAM,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE;oBAC5C,MAAM,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC;iBAC5B,CAAC,CAAC,CAAA;YACL,CAAC,CAAC,CAAA;YAEF,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBACnB,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC;oBACrC,QAAQ;iBACT,CAAC,CAAA;gBACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,CAAA,CAAC,CAAC,CAAC,CAAA;gBAElD,KAAK,CAAC,KAAK,IAAI,EAAE;oBACf,MAAM,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;oBACnC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;gBACtB,CAAC,CAAC,EAAE,CAAA;YACN,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/src/connection/index.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { expect } from 'aegir/chai'
|
|
2
|
-
import sinon from 'sinon'
|
|
3
|
-
import type { TestSetup } from '../index.js'
|
|
4
|
-
import type { Connection } from '@libp2p/interface'
|
|
5
|
-
|
|
6
|
-
export default (test: TestSetup<Connection>): void => {
|
|
7
|
-
describe('connection', () => {
|
|
8
|
-
describe('open connection', () => {
|
|
9
|
-
let connection: Connection
|
|
10
|
-
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
connection = await test.setup()
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
afterEach(async () => {
|
|
16
|
-
await connection.close()
|
|
17
|
-
await test.teardown()
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('should have properties set', () => {
|
|
21
|
-
expect(connection.id).to.exist()
|
|
22
|
-
expect(connection.remotePeer).to.exist()
|
|
23
|
-
expect(connection.remoteAddr).to.exist()
|
|
24
|
-
expect(connection.status).to.equal('open')
|
|
25
|
-
expect(connection.timeline.open).to.exist()
|
|
26
|
-
expect(connection.timeline.close).to.not.exist()
|
|
27
|
-
expect(connection.direction).to.exist()
|
|
28
|
-
expect(connection.streams).to.eql([])
|
|
29
|
-
expect(connection.tags).to.eql([])
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should get the metadata of an open connection', () => {
|
|
33
|
-
expect(connection.status).to.equal('open')
|
|
34
|
-
expect(connection.direction).to.exist()
|
|
35
|
-
expect(connection.timeline.open).to.exist()
|
|
36
|
-
expect(connection.timeline.close).to.not.exist()
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should return an empty array of streams', () => {
|
|
40
|
-
const streams = connection.streams
|
|
41
|
-
|
|
42
|
-
expect(streams).to.eql([])
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('should be able to create a new stream', async () => {
|
|
46
|
-
expect(connection.streams).to.be.empty()
|
|
47
|
-
|
|
48
|
-
const protocolToUse = '/echo/0.0.1'
|
|
49
|
-
const stream = await connection.newStream([protocolToUse])
|
|
50
|
-
|
|
51
|
-
expect(stream).to.have.property('protocol', protocolToUse)
|
|
52
|
-
|
|
53
|
-
const connStreams = connection.streams
|
|
54
|
-
|
|
55
|
-
expect(stream).to.exist()
|
|
56
|
-
expect(connStreams).to.exist()
|
|
57
|
-
expect(connStreams).to.have.lengthOf(1)
|
|
58
|
-
expect(connStreams[0]).to.equal(stream)
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
describe('close connection', () => {
|
|
63
|
-
let connection: Connection
|
|
64
|
-
let timelineProxy
|
|
65
|
-
const proxyHandler = {
|
|
66
|
-
set () {
|
|
67
|
-
// @ts-expect-error - TS fails to infer here
|
|
68
|
-
return Reflect.set(...arguments)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
beforeEach(async () => {
|
|
73
|
-
timelineProxy = new Proxy({
|
|
74
|
-
open: Date.now() - 10,
|
|
75
|
-
upgraded: Date.now()
|
|
76
|
-
}, proxyHandler)
|
|
77
|
-
|
|
78
|
-
connection = await test.setup()
|
|
79
|
-
connection.timeline = timelineProxy
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
afterEach(async () => {
|
|
83
|
-
await test.teardown()
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('should be able to close the connection after being created', async () => {
|
|
87
|
-
expect(connection.timeline.close).to.not.exist()
|
|
88
|
-
await connection.close()
|
|
89
|
-
|
|
90
|
-
expect(connection.timeline.close).to.exist()
|
|
91
|
-
expect(connection.status).to.equal('closed')
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('should be able to close the connection after opening a stream', async () => {
|
|
95
|
-
// Open stream
|
|
96
|
-
const protocol = '/echo/0.0.1'
|
|
97
|
-
await connection.newStream([protocol])
|
|
98
|
-
|
|
99
|
-
// Close connection
|
|
100
|
-
expect(connection.timeline.close).to.not.exist()
|
|
101
|
-
await connection.close()
|
|
102
|
-
|
|
103
|
-
expect(connection.timeline.close).to.exist()
|
|
104
|
-
expect(connection.status).to.equal('closed')
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('should properly track streams', async () => {
|
|
108
|
-
// Open stream
|
|
109
|
-
const protocol = '/echo/0.0.1'
|
|
110
|
-
const stream = await connection.newStream([protocol])
|
|
111
|
-
expect(stream).to.have.property('protocol', protocol)
|
|
112
|
-
|
|
113
|
-
// Close stream
|
|
114
|
-
await stream.close()
|
|
115
|
-
|
|
116
|
-
expect(connection.streams.filter(s => s.id === stream.id)).to.be.empty()
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
it('should track outbound streams', async () => {
|
|
120
|
-
// Open stream
|
|
121
|
-
const protocol = '/echo/0.0.1'
|
|
122
|
-
const stream = await connection.newStream(protocol)
|
|
123
|
-
expect(stream).to.have.property('direction', 'outbound')
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('should support a proxy on the timeline', async () => {
|
|
127
|
-
sinon.spy(proxyHandler, 'set')
|
|
128
|
-
expect(connection.timeline.close).to.not.exist()
|
|
129
|
-
|
|
130
|
-
await connection.close()
|
|
131
|
-
// @ts-expect-error - fails to infer callCount
|
|
132
|
-
expect(proxyHandler.set.callCount).to.equal(1)
|
|
133
|
-
// @ts-expect-error - fails to infer getCall
|
|
134
|
-
const [obj, key, value] = proxyHandler.set.getCall(0).args
|
|
135
|
-
expect(obj).to.eql(connection.timeline)
|
|
136
|
-
expect(key).to.equal('close')
|
|
137
|
-
expect(value).to.be.a('number').that.equals(connection.timeline.close)
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
it('should fail to create a new stream if the connection is closing', async () => {
|
|
141
|
-
expect(connection.timeline.close).to.not.exist()
|
|
142
|
-
const p = connection.close()
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
const protocol = '/echo/0.0.1'
|
|
146
|
-
await connection.newStream([protocol])
|
|
147
|
-
} catch (err: any) {
|
|
148
|
-
expect(err).to.exist()
|
|
149
|
-
return
|
|
150
|
-
} finally {
|
|
151
|
-
await p
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
throw new Error('should fail to create a new stream if the connection is closing')
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
it('should fail to create a new stream if the connection is closed', async () => {
|
|
158
|
-
expect(connection.timeline.close).to.not.exist()
|
|
159
|
-
await connection.close()
|
|
160
|
-
|
|
161
|
-
await expect(connection.newStream(['/echo/0.0.1'])).to.eventually.be.rejected
|
|
162
|
-
.with.property('name', 'ConnectionClosedError')
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ConnectionGater } from '@libp2p/interface'
|
|
2
|
-
|
|
3
|
-
export function mockConnectionGater (): ConnectionGater {
|
|
4
|
-
return {
|
|
5
|
-
denyDialPeer: async () => Promise.resolve(false),
|
|
6
|
-
denyDialMultiaddr: async () => Promise.resolve(false),
|
|
7
|
-
denyInboundConnection: async () => Promise.resolve(false),
|
|
8
|
-
denyOutboundConnection: async () => Promise.resolve(false),
|
|
9
|
-
denyInboundEncryptedConnection: async () => Promise.resolve(false),
|
|
10
|
-
denyOutboundEncryptedConnection: async () => Promise.resolve(false),
|
|
11
|
-
denyInboundUpgradedConnection: async () => Promise.resolve(false),
|
|
12
|
-
denyOutboundUpgradedConnection: async () => Promise.resolve(false),
|
|
13
|
-
denyInboundRelayReservation: async () => Promise.resolve(false),
|
|
14
|
-
denyOutboundRelayedConnection: async () => Promise.resolve(false),
|
|
15
|
-
denyInboundRelayedConnection: async () => Promise.resolve(false),
|
|
16
|
-
filterMultiaddrForPeer: async () => Promise.resolve(true)
|
|
17
|
-
}
|
|
18
|
-
}
|