@libp2p/interface-compliance-tests 4.1.4 → 4.1.5-0b4a2ee79
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 +1 -1
- package/dist/src/connection-encryption/utils/index.d.ts.map +1 -1
- package/dist/src/connection-encryption/utils/index.js +3 -1
- package/dist/src/connection-encryption/utils/index.js.map +1 -1
- package/dist/src/mocks/connection-manager.d.ts +2 -1
- package/dist/src/mocks/connection-manager.d.ts.map +1 -1
- package/dist/src/mocks/connection-manager.js.map +1 -1
- package/dist/src/mocks/connection.d.ts +2 -0
- package/dist/src/mocks/connection.d.ts.map +1 -1
- package/dist/src/mocks/connection.js +56 -12
- package/dist/src/mocks/connection.js.map +1 -1
- package/dist/src/mocks/index.d.ts +0 -1
- package/dist/src/mocks/index.d.ts.map +1 -1
- package/dist/src/mocks/index.js +0 -1
- package/dist/src/mocks/index.js.map +1 -1
- package/dist/src/mocks/multiaddr-connection.d.ts.map +1 -1
- package/dist/src/mocks/multiaddr-connection.js +6 -2
- package/dist/src/mocks/multiaddr-connection.js.map +1 -1
- package/dist/src/mocks/muxer.d.ts +1 -1
- package/dist/src/mocks/muxer.d.ts.map +1 -1
- package/dist/src/mocks/muxer.js +17 -5
- package/dist/src/mocks/muxer.js.map +1 -1
- package/dist/src/mocks/peer-discovery.d.ts.map +1 -1
- package/dist/src/mocks/peer-discovery.js +1 -2
- package/dist/src/mocks/peer-discovery.js.map +1 -1
- package/dist/src/pubsub/api.d.ts.map +1 -1
- package/dist/src/pubsub/api.js +0 -2
- package/dist/src/pubsub/api.js.map +1 -1
- package/dist/src/pubsub/index.d.ts +2 -0
- package/dist/src/pubsub/index.d.ts.map +1 -1
- package/dist/src/pubsub/index.js.map +1 -1
- package/dist/src/pubsub/two-nodes.js +3 -3
- package/dist/src/pubsub/two-nodes.js.map +1 -1
- package/dist/src/pubsub/utils.d.ts.map +1 -1
- package/dist/src/pubsub/utils.js +3 -1
- package/dist/src/pubsub/utils.js.map +1 -1
- package/dist/src/stream-muxer/close-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/close-test.js +42 -11
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/package.json +15 -15
- package/src/connection-encryption/utils/index.ts +3 -1
- package/src/mocks/connection-manager.ts +2 -1
- package/src/mocks/connection.ts +64 -14
- package/src/mocks/index.ts +0 -1
- package/src/mocks/multiaddr-connection.ts +6 -2
- package/src/mocks/muxer.ts +20 -7
- package/src/mocks/peer-discovery.ts +1 -2
- package/src/pubsub/api.ts +0 -2
- package/src/pubsub/index.ts +2 -0
- package/src/pubsub/two-nodes.ts +3 -3
- package/src/pubsub/utils.ts +3 -1
- package/src/stream-muxer/close-test.ts +47 -9
- 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 -98
- package/dist/src/mocks/connection-encrypter.js.map +0 -1
- package/dist/typedoc-urls.json +0 -39
- package/src/mocks/connection-encrypter.ts +0 -113
package/src/pubsub/two-nodes.ts
CHANGED
|
@@ -73,7 +73,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>): void => {
|
|
|
73
73
|
expect(psA.getTopics()).to.deep.equal([topic])
|
|
74
74
|
expect(psB.getPeers()).to.have.lengthOf(1)
|
|
75
75
|
expect(psB.getSubscribers(topic).map(p => p.toString())).to.deep.equal([componentsA.peerId.toString()])
|
|
76
|
-
expect(changedPeerId).to.
|
|
76
|
+
expect(changedPeerId.toString()).to.equal(psB.getPeers()[0].toString())
|
|
77
77
|
expect(changedSubs).to.have.lengthOf(1)
|
|
78
78
|
expect(changedSubs[0].topic).to.equal(topic)
|
|
79
79
|
expect(changedSubs[0].subscribe).to.equal(true)
|
|
@@ -243,7 +243,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>): void => {
|
|
|
243
243
|
const { peerId: changedPeerId, subscriptions: changedSubs } = evt.detail
|
|
244
244
|
expect(psB.getPeers()).to.have.lengthOf(1)
|
|
245
245
|
expect(psB.getTopics()).to.be.empty()
|
|
246
|
-
expect(changedPeerId).to.
|
|
246
|
+
expect(changedPeerId.toString()).to.equal(psB.getPeers()[0].toString())
|
|
247
247
|
expect(changedSubs).to.have.lengthOf(1)
|
|
248
248
|
expect(changedSubs[0].topic).to.equal(topic)
|
|
249
249
|
expect(changedSubs[0].subscribe).to.equal(true)
|
|
@@ -252,7 +252,7 @@ export default (common: TestSetup<PubSub, PubSubArgs>): void => {
|
|
|
252
252
|
const { peerId: changedPeerId, subscriptions: changedSubs } = evt.detail
|
|
253
253
|
expect(psB.getPeers()).to.have.lengthOf(1)
|
|
254
254
|
expect(psB.getTopics()).to.be.empty()
|
|
255
|
-
expect(changedPeerId).to.
|
|
255
|
+
expect(changedPeerId.toString()).to.equal(psB.getPeers()[0].toString())
|
|
256
256
|
expect(changedSubs).to.have.lengthOf(1)
|
|
257
257
|
expect(changedSubs[0].topic).to.equal(topic)
|
|
258
258
|
expect(changedSubs[0].subscribe).to.equal(false)
|
package/src/pubsub/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TypedEventEmitter } from '@libp2p/interface/events'
|
|
2
|
+
import { defaultLogger } from '@libp2p/logger'
|
|
2
3
|
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
3
4
|
import { pEvent } from 'p-event'
|
|
4
5
|
import pWaitFor from 'p-wait-for'
|
|
@@ -19,7 +20,8 @@ export async function createComponents (): Promise<MockNetworkComponents> {
|
|
|
19
20
|
const components: any = {
|
|
20
21
|
peerId: await createEd25519PeerId(),
|
|
21
22
|
registrar: mockRegistrar(),
|
|
22
|
-
events: new TypedEventEmitter()
|
|
23
|
+
events: new TypedEventEmitter(),
|
|
24
|
+
logger: defaultLogger()
|
|
23
25
|
}
|
|
24
26
|
components.connectionManager = mockConnectionManager(components)
|
|
25
27
|
|
|
@@ -19,13 +19,51 @@ function randomBuffer (): Uint8Array {
|
|
|
19
19
|
return uint8ArrayFromString(Math.random().toString())
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
function infiniteRandom (): AsyncGenerator<Uint8ArrayList, void, unknown> {
|
|
23
|
+
let done: Error | boolean = false
|
|
24
|
+
|
|
25
|
+
const generator: AsyncGenerator<Uint8ArrayList, void, unknown> = {
|
|
26
|
+
[Symbol.asyncIterator]: () => {
|
|
27
|
+
return generator
|
|
28
|
+
},
|
|
29
|
+
async next () {
|
|
30
|
+
await delay(10)
|
|
31
|
+
|
|
32
|
+
if (done instanceof Error) {
|
|
33
|
+
throw done
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (done) {
|
|
37
|
+
return {
|
|
38
|
+
done: true,
|
|
39
|
+
value: undefined
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
done: false,
|
|
45
|
+
value: new Uint8ArrayList(randomBuffer())
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
async return (): Promise<IteratorReturnResult<void>> {
|
|
49
|
+
done = true
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
done: true,
|
|
53
|
+
value: undefined
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
async throw (err: Error): Promise<IteratorReturnResult<void>> {
|
|
57
|
+
done = err
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
done: true,
|
|
61
|
+
value: undefined
|
|
62
|
+
}
|
|
27
63
|
}
|
|
28
64
|
}
|
|
65
|
+
|
|
66
|
+
return generator
|
|
29
67
|
}
|
|
30
68
|
|
|
31
69
|
export default (common: TestSetup<StreamMuxerFactory>): void => {
|
|
@@ -55,7 +93,7 @@ export default (common: TestSetup<StreamMuxerFactory>): void => {
|
|
|
55
93
|
void Promise.all(
|
|
56
94
|
streams.map(async stream => {
|
|
57
95
|
await pipe(
|
|
58
|
-
infiniteRandom,
|
|
96
|
+
infiniteRandom(),
|
|
59
97
|
stream,
|
|
60
98
|
drain
|
|
61
99
|
)
|
|
@@ -97,7 +135,7 @@ export default (common: TestSetup<StreamMuxerFactory>): void => {
|
|
|
97
135
|
void Promise.all(
|
|
98
136
|
streams.map(async stream => {
|
|
99
137
|
await pipe(
|
|
100
|
-
infiniteRandom,
|
|
138
|
+
infiniteRandom(),
|
|
101
139
|
stream,
|
|
102
140
|
drain
|
|
103
141
|
)
|
|
@@ -139,7 +177,7 @@ export default (common: TestSetup<StreamMuxerFactory>): void => {
|
|
|
139
177
|
|
|
140
178
|
const streamPipes = streams.map(async stream => {
|
|
141
179
|
await pipe(
|
|
142
|
-
infiniteRandom,
|
|
180
|
+
infiniteRandom(),
|
|
143
181
|
stream,
|
|
144
182
|
drain
|
|
145
183
|
)
|
|
@@ -213,7 +251,7 @@ export default (common: TestSetup<StreamMuxerFactory>): void => {
|
|
|
213
251
|
controllers.push(controller)
|
|
214
252
|
|
|
215
253
|
try {
|
|
216
|
-
const abortableRand = abortableSource(infiniteRandom, controller.signal, { abortCode: 'ERR_TEST_ABORT' })
|
|
254
|
+
const abortableRand = abortableSource(infiniteRandom(), controller.signal, { abortCode: 'ERR_TEST_ABORT' })
|
|
217
255
|
await pipe(abortableRand, stream, drain)
|
|
218
256
|
} catch (err: any) {
|
|
219
257
|
if (err.code !== 'ERR_TEST_ABORT') throw err
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-encrypter.d.ts","sourceRoot":"","sources":["../../../src/mocks/connection-encrypter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAYjF,wBAAgB,uBAAuB,IAAK,mBAAmB,CA6F9D"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { UnexpectedPeerError } from '@libp2p/interface/errors';
|
|
2
|
-
import { peerIdFromBytes } from '@libp2p/peer-id';
|
|
3
|
-
import { multiaddr } from '@multiformats/multiaddr';
|
|
4
|
-
import { handshake } from 'it-handshake';
|
|
5
|
-
import map from 'it-map';
|
|
6
|
-
import { duplexPair } from 'it-pair/duplex';
|
|
7
|
-
import { pipe } from 'it-pipe';
|
|
8
|
-
// A basic transform that does nothing to the data
|
|
9
|
-
const transform = () => {
|
|
10
|
-
return (source) => (async function* () {
|
|
11
|
-
for await (const chunk of source) {
|
|
12
|
-
yield chunk;
|
|
13
|
-
}
|
|
14
|
-
})();
|
|
15
|
-
};
|
|
16
|
-
export function mockConnectionEncrypter() {
|
|
17
|
-
const encrypter = {
|
|
18
|
-
protocol: 'insecure',
|
|
19
|
-
secureInbound: async (localPeer, duplex, expectedPeer) => {
|
|
20
|
-
// 1. Perform a basic handshake.
|
|
21
|
-
const shake = handshake(duplex);
|
|
22
|
-
shake.write(localPeer.toBytes());
|
|
23
|
-
const remoteId = await shake.read();
|
|
24
|
-
if (remoteId == null) {
|
|
25
|
-
throw new Error('Could not read remote ID');
|
|
26
|
-
}
|
|
27
|
-
const remotePeer = peerIdFromBytes(remoteId.slice());
|
|
28
|
-
shake.rest();
|
|
29
|
-
if (expectedPeer?.equals(remotePeer) === false) {
|
|
30
|
-
throw new UnexpectedPeerError();
|
|
31
|
-
}
|
|
32
|
-
// 2. Create your encryption box/unbox wrapper
|
|
33
|
-
const wrapper = duplexPair();
|
|
34
|
-
const encrypt = transform(); // Use transform iterables to modify data
|
|
35
|
-
const decrypt = transform();
|
|
36
|
-
void pipe(wrapper[0], // We write to wrapper
|
|
37
|
-
encrypt, // The data is encrypted
|
|
38
|
-
shake.stream, // It goes to the remote peer
|
|
39
|
-
// It goes to the remote peer
|
|
40
|
-
source => map(source, (list) => list.subarray()), // turn lists into arrays
|
|
41
|
-
decrypt, // Decrypt the incoming data
|
|
42
|
-
wrapper[0] // Pipe to the wrapper
|
|
43
|
-
);
|
|
44
|
-
return {
|
|
45
|
-
conn: {
|
|
46
|
-
...wrapper[1],
|
|
47
|
-
close: async () => { },
|
|
48
|
-
localAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
|
|
49
|
-
remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4002'),
|
|
50
|
-
timeline: {
|
|
51
|
-
open: Date.now()
|
|
52
|
-
},
|
|
53
|
-
conn: true
|
|
54
|
-
},
|
|
55
|
-
remotePeer,
|
|
56
|
-
remoteExtensions: {}
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
secureOutbound: async (localPeer, duplex, remotePeer) => {
|
|
60
|
-
// 1. Perform a basic handshake.
|
|
61
|
-
const shake = handshake(duplex);
|
|
62
|
-
shake.write(localPeer.toBytes());
|
|
63
|
-
const remoteId = await shake.read();
|
|
64
|
-
if (remoteId == null) {
|
|
65
|
-
throw new Error('Could not read remote ID');
|
|
66
|
-
}
|
|
67
|
-
shake.rest();
|
|
68
|
-
// 2. Create your encryption box/unbox wrapper
|
|
69
|
-
const wrapper = duplexPair();
|
|
70
|
-
const encrypt = transform();
|
|
71
|
-
const decrypt = transform();
|
|
72
|
-
void pipe(wrapper[0], // We write to wrapper
|
|
73
|
-
encrypt, // The data is encrypted
|
|
74
|
-
shake.stream, // It goes to the remote peer
|
|
75
|
-
// It goes to the remote peer
|
|
76
|
-
source => map(source, (list) => list.subarray()), // turn lists into arrays
|
|
77
|
-
decrypt, // Decrypt the incoming data
|
|
78
|
-
wrapper[0] // Pipe to the wrapper
|
|
79
|
-
);
|
|
80
|
-
return {
|
|
81
|
-
conn: {
|
|
82
|
-
...wrapper[1],
|
|
83
|
-
close: async () => { },
|
|
84
|
-
localAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
|
|
85
|
-
remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4002'),
|
|
86
|
-
timeline: {
|
|
87
|
-
open: Date.now()
|
|
88
|
-
},
|
|
89
|
-
conn: true
|
|
90
|
-
},
|
|
91
|
-
remotePeer: peerIdFromBytes(remoteId.slice()),
|
|
92
|
-
remoteExtensions: {}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
return encrypter;
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=connection-encrypter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-encrypter.js","sourceRoot":"","sources":["../../../src/mocks/connection-encrypter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAI9B,kDAAkD;AAClD,MAAM,SAAS,GAAG,GAA+C,EAAE;IACjE,OAAO,CAAC,MAAiB,EAAE,EAAE,CAAC,CAAC,KAAK,SAAU,CAAC;QAC7C,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE;YAChC,MAAM,KAAK,CAAA;SACZ;IACH,CAAC,CAAC,EAAE,CAAA;AACN,CAAC,CAAA;AAED,MAAM,UAAU,uBAAuB;IACrC,MAAM,SAAS,GAAwB;QACrC,QAAQ,EAAE,UAAU;QACpB,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE;YACvD,gCAAgC;YAChC,MAAM,KAAK,GAAG,SAAS,CAAa,MAAM,CAAC,CAAA;YAC3C,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAA;YAChC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;YAEnC,IAAI,QAAQ,IAAI,IAAI,EAAE;gBACpB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CA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AAO,SAAS,CAAA;AAClB,CAAC"}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.connection.default.html",
|
|
3
|
-
"./connection:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.connection.default.html",
|
|
4
|
-
"./connection-encryption:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.connection_encryption.default.html",
|
|
5
|
-
"TestSetup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.index.TestSetup.html",
|
|
6
|
-
".:TestSetup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.index.TestSetup.html",
|
|
7
|
-
"isValidTick": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.is_valid_tick.isValidTick.html",
|
|
8
|
-
"./is-valid-tick:isValidTick": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.is_valid_tick.isValidTick.html",
|
|
9
|
-
"MockNetworkComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.mocks.MockNetworkComponents.html",
|
|
10
|
-
"MockUpgraderInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.mocks.MockUpgraderInit.html",
|
|
11
|
-
"mockNetwork": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface_compliance_tests.mocks.mockNetwork.html",
|
|
12
|
-
"connectionPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.connectionPair.html",
|
|
13
|
-
"mockConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockConnection.html",
|
|
14
|
-
"mockConnectionEncrypter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockConnectionEncrypter.html",
|
|
15
|
-
"mockConnectionGater": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockConnectionGater.html",
|
|
16
|
-
"mockConnectionManager": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockConnectionManager.html",
|
|
17
|
-
"mockDuplex": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockDuplex.html",
|
|
18
|
-
"mockMetrics": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockMetrics.html",
|
|
19
|
-
"mockMultiaddrConnPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockMultiaddrConnPair.html",
|
|
20
|
-
"mockMultiaddrConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockMultiaddrConnection.html",
|
|
21
|
-
"mockMuxer": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockMuxer.html",
|
|
22
|
-
"mockRegistrar": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockRegistrar.html",
|
|
23
|
-
"mockStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockStream.html",
|
|
24
|
-
"mockUpgrader": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.mockUpgrader.html",
|
|
25
|
-
"streamPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.mocks.streamPair.html",
|
|
26
|
-
"./peer-discovery:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.peer_discovery.default.html",
|
|
27
|
-
"./peers:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface_compliance_tests.peers.default.html",
|
|
28
|
-
"PubSubArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.pubsub.PubSubArgs.html",
|
|
29
|
-
"./pubsub:PubSubArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.pubsub.PubSubArgs.html",
|
|
30
|
-
"PubSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.pubsub.PubSubComponents.html",
|
|
31
|
-
"./pubsub:PubSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.pubsub.PubSubComponents.html",
|
|
32
|
-
"./pubsub:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.pubsub.default.html",
|
|
33
|
-
"./stream-muxer:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.stream_muxer.default.html",
|
|
34
|
-
"Connector": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.transport.Connector.html",
|
|
35
|
-
"./transport:Connector": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.transport.Connector.html",
|
|
36
|
-
"TransportTestFixtures": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.transport.TransportTestFixtures.html",
|
|
37
|
-
"./transport:TransportTestFixtures": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface_compliance_tests.transport.TransportTestFixtures.html",
|
|
38
|
-
"./transport:default": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface_compliance_tests.transport.default.html"
|
|
39
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { UnexpectedPeerError } from '@libp2p/interface/errors'
|
|
2
|
-
import { peerIdFromBytes } from '@libp2p/peer-id'
|
|
3
|
-
import { multiaddr } from '@multiformats/multiaddr'
|
|
4
|
-
import { handshake } from 'it-handshake'
|
|
5
|
-
import map from 'it-map'
|
|
6
|
-
import { duplexPair } from 'it-pair/duplex'
|
|
7
|
-
import { pipe } from 'it-pipe'
|
|
8
|
-
import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter'
|
|
9
|
-
import type { Transform, Source } from 'it-stream-types'
|
|
10
|
-
|
|
11
|
-
// A basic transform that does nothing to the data
|
|
12
|
-
const transform = <T>(): Transform<Source<T>, AsyncGenerator<T>> => {
|
|
13
|
-
return (source: Source<T>) => (async function * () {
|
|
14
|
-
for await (const chunk of source) {
|
|
15
|
-
yield chunk
|
|
16
|
-
}
|
|
17
|
-
})()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function mockConnectionEncrypter (): ConnectionEncrypter {
|
|
21
|
-
const encrypter: ConnectionEncrypter = {
|
|
22
|
-
protocol: 'insecure',
|
|
23
|
-
secureInbound: async (localPeer, duplex, expectedPeer) => {
|
|
24
|
-
// 1. Perform a basic handshake.
|
|
25
|
-
const shake = handshake<Uint8Array>(duplex)
|
|
26
|
-
shake.write(localPeer.toBytes())
|
|
27
|
-
const remoteId = await shake.read()
|
|
28
|
-
|
|
29
|
-
if (remoteId == null) {
|
|
30
|
-
throw new Error('Could not read remote ID')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const remotePeer = peerIdFromBytes(remoteId.slice())
|
|
34
|
-
shake.rest()
|
|
35
|
-
|
|
36
|
-
if (expectedPeer?.equals(remotePeer) === false) {
|
|
37
|
-
throw new UnexpectedPeerError()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 2. Create your encryption box/unbox wrapper
|
|
41
|
-
const wrapper = duplexPair<Uint8Array>()
|
|
42
|
-
const encrypt = transform<Uint8Array>() // Use transform iterables to modify data
|
|
43
|
-
const decrypt = transform<Uint8Array>()
|
|
44
|
-
|
|
45
|
-
void pipe(
|
|
46
|
-
wrapper[0], // We write to wrapper
|
|
47
|
-
encrypt, // The data is encrypted
|
|
48
|
-
shake.stream, // It goes to the remote peer
|
|
49
|
-
source => map(source, (list) => list.subarray()), // turn lists into arrays
|
|
50
|
-
decrypt, // Decrypt the incoming data
|
|
51
|
-
wrapper[0] // Pipe to the wrapper
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
conn: {
|
|
56
|
-
...wrapper[1],
|
|
57
|
-
close: async () => { },
|
|
58
|
-
localAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
|
|
59
|
-
remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4002'),
|
|
60
|
-
timeline: {
|
|
61
|
-
open: Date.now()
|
|
62
|
-
},
|
|
63
|
-
conn: true
|
|
64
|
-
},
|
|
65
|
-
remotePeer,
|
|
66
|
-
remoteExtensions: {}
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
secureOutbound: async (localPeer, duplex, remotePeer) => {
|
|
70
|
-
// 1. Perform a basic handshake.
|
|
71
|
-
const shake = handshake<Uint8Array>(duplex)
|
|
72
|
-
shake.write(localPeer.toBytes())
|
|
73
|
-
const remoteId = await shake.read()
|
|
74
|
-
|
|
75
|
-
if (remoteId == null) {
|
|
76
|
-
throw new Error('Could not read remote ID')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
shake.rest()
|
|
80
|
-
|
|
81
|
-
// 2. Create your encryption box/unbox wrapper
|
|
82
|
-
const wrapper = duplexPair<Uint8Array>()
|
|
83
|
-
const encrypt = transform<Uint8Array>()
|
|
84
|
-
const decrypt = transform<Uint8Array>()
|
|
85
|
-
|
|
86
|
-
void pipe(
|
|
87
|
-
wrapper[0], // We write to wrapper
|
|
88
|
-
encrypt, // The data is encrypted
|
|
89
|
-
shake.stream, // It goes to the remote peer
|
|
90
|
-
source => map(source, (list) => list.subarray()), // turn lists into arrays
|
|
91
|
-
decrypt, // Decrypt the incoming data
|
|
92
|
-
wrapper[0] // Pipe to the wrapper
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
conn: {
|
|
97
|
-
...wrapper[1],
|
|
98
|
-
close: async () => { },
|
|
99
|
-
localAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
|
|
100
|
-
remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4002'),
|
|
101
|
-
timeline: {
|
|
102
|
-
open: Date.now()
|
|
103
|
-
},
|
|
104
|
-
conn: true
|
|
105
|
-
},
|
|
106
|
-
remotePeer: peerIdFromBytes(remoteId.slice()),
|
|
107
|
-
remoteExtensions: {}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return encrypter
|
|
113
|
-
}
|