@libp2p/interface-compliance-tests 1.1.29 → 1.1.30
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/mocks/connection-manager.d.ts +21 -7
- package/dist/src/mocks/connection-manager.d.ts.map +1 -1
- package/dist/src/mocks/connection-manager.js +97 -9
- package/dist/src/mocks/connection-manager.js.map +1 -1
- package/dist/src/mocks/index.d.ts +1 -1
- package/dist/src/mocks/index.d.ts.map +1 -1
- package/dist/src/mocks/index.js +1 -1
- package/dist/src/mocks/index.js.map +1 -1
- package/dist/src/mocks/registrar.d.ts +0 -2
- package/dist/src/mocks/registrar.d.ts.map +1 -1
- package/dist/src/mocks/registrar.js +1 -12
- package/dist/src/mocks/registrar.js.map +1 -1
- package/dist/src/pubsub/api.d.ts.map +1 -1
- package/dist/src/pubsub/api.js +13 -10
- package/dist/src/pubsub/api.js.map +1 -1
- package/dist/src/pubsub/connection-handlers.d.ts.map +1 -1
- package/dist/src/pubsub/connection-handlers.js +43 -37
- package/dist/src/pubsub/connection-handlers.js.map +1 -1
- package/dist/src/pubsub/emit-self.d.ts.map +1 -1
- package/dist/src/pubsub/emit-self.js +22 -18
- package/dist/src/pubsub/emit-self.js.map +1 -1
- package/dist/src/pubsub/messages.d.ts.map +1 -1
- package/dist/src/pubsub/messages.js +7 -4
- package/dist/src/pubsub/messages.js.map +1 -1
- package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -1
- package/dist/src/pubsub/multiple-nodes.js +33 -33
- package/dist/src/pubsub/multiple-nodes.js.map +1 -1
- package/dist/src/pubsub/two-nodes.d.ts.map +1 -1
- package/dist/src/pubsub/two-nodes.js +10 -8
- 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 +4 -1
- package/dist/src/pubsub/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/mocks/connection-manager.ts +125 -11
- package/src/mocks/index.ts +1 -1
- package/src/mocks/registrar.ts +1 -16
- package/src/pubsub/api.ts +13 -10
- package/src/pubsub/connection-handlers.ts +45 -37
- package/src/pubsub/emit-self.ts +24 -19
- package/src/pubsub/messages.ts +7 -4
- package/src/pubsub/multiple-nodes.ts +35 -35
- package/src/pubsub/two-nodes.ts +11 -10
- package/src/pubsub/utils.ts +6 -1
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
import { EventEmitter } from '@libp2p/interfaces';
|
|
1
|
+
import { EventEmitter, Startable } from '@libp2p/interfaces';
|
|
2
2
|
import type { Connection } from '@libp2p/interfaces/connection';
|
|
3
3
|
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
4
|
-
import type { ConnectionManager, ConnectionManagerEvents } from '@libp2p/interfaces/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import type { ConnectionManager, ConnectionManagerEvents } from '@libp2p/interfaces/connection-manager';
|
|
5
|
+
import type { Components, Initializable } from '@libp2p/interfaces/src/components';
|
|
6
|
+
declare class MockNetwork {
|
|
7
|
+
private components;
|
|
8
|
+
addNode(components: Components): void;
|
|
9
|
+
getNode(peerId: PeerId): Components;
|
|
10
|
+
reset(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare const mockNetwork: MockNetwork;
|
|
13
|
+
declare class MockConnectionManager extends EventEmitter<ConnectionManagerEvents> implements ConnectionManager, Initializable, Startable {
|
|
14
|
+
private connections;
|
|
15
|
+
private components?;
|
|
16
|
+
private started;
|
|
17
|
+
init(components: Components): void;
|
|
18
|
+
isStarted(): boolean;
|
|
19
|
+
start(): Promise<void>;
|
|
20
|
+
stop(): Promise<void>;
|
|
21
|
+
getConnections(peerId?: PeerId): Connection[];
|
|
22
|
+
openConnection(peerId: PeerId): Promise<Connection>;
|
|
23
|
+
closeConnections(peerId: PeerId): Promise<void>;
|
|
10
24
|
}
|
|
11
25
|
export declare function mockConnectionManager(): MockConnectionManager;
|
|
12
26
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../../../src/mocks/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../../../src/mocks/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAA;AACvG,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AAIlF,cAAM,WAAW;IACf,OAAO,CAAC,UAAU,CAAmB;IAErC,OAAO,CAAE,UAAU,EAAE,UAAU,GAAG,IAAI;IAItC,OAAO,CAAE,MAAM,EAAE,MAAM,GAAG,UAAU;IAUpC,KAAK;CAGN;AAED,eAAO,MAAM,WAAW,aAAoB,CAAA;AAE5C,cAAM,qBAAsB,SAAQ,YAAY,CAAC,uBAAuB,CAAE,YAAW,iBAAiB,EAAE,aAAa,EAAE,SAAS;IAC9H,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,UAAU,CAAC,CAAY;IAC/B,OAAO,CAAC,OAAO,CAAQ;IAEvB,IAAI,CAAE,UAAU,EAAE,UAAU;IAI5B,SAAS;IAIH,KAAK;IAIL,IAAI;IAQV,cAAc,CAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE;IASxC,cAAc,CAAE,MAAM,EAAE,MAAM;IA0C9B,gBAAgB,CAAE,MAAM,EAAE,MAAM;CA2BvC;AAED,wBAAgB,qBAAqB,0BAEpC"}
|
|
@@ -1,16 +1,104 @@
|
|
|
1
|
-
import { EventEmitter } from '@libp2p/interfaces';
|
|
1
|
+
import { CustomEvent, EventEmitter } from '@libp2p/interfaces';
|
|
2
|
+
import { connectionPair } from './connection.js';
|
|
3
|
+
import errCode from 'err-code';
|
|
4
|
+
class MockNetwork {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.components = [];
|
|
7
|
+
}
|
|
8
|
+
addNode(components) {
|
|
9
|
+
this.components.push(components);
|
|
10
|
+
}
|
|
11
|
+
getNode(peerId) {
|
|
12
|
+
for (const components of this.components) {
|
|
13
|
+
if (peerId.equals(components.getPeerId())) {
|
|
14
|
+
return components;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
throw errCode(new Error('Peer not found'), 'ERR_PEER_NOT_FOUND');
|
|
18
|
+
}
|
|
19
|
+
reset() {
|
|
20
|
+
this.components = [];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const mockNetwork = new MockNetwork();
|
|
2
24
|
class MockConnectionManager extends EventEmitter {
|
|
3
|
-
|
|
4
|
-
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.connections = [];
|
|
28
|
+
this.started = false;
|
|
29
|
+
}
|
|
30
|
+
init(components) {
|
|
31
|
+
this.components = components;
|
|
32
|
+
}
|
|
33
|
+
isStarted() {
|
|
34
|
+
return this.started;
|
|
35
|
+
}
|
|
36
|
+
async start() {
|
|
37
|
+
this.started = true;
|
|
38
|
+
}
|
|
39
|
+
async stop() {
|
|
40
|
+
for (const connection of this.connections) {
|
|
41
|
+
await this.closeConnections(connection.remotePeer);
|
|
42
|
+
}
|
|
43
|
+
this.started = false;
|
|
5
44
|
}
|
|
6
|
-
|
|
7
|
-
|
|
45
|
+
getConnections(peerId) {
|
|
46
|
+
if (peerId != null) {
|
|
47
|
+
return this.connections
|
|
48
|
+
.filter(c => c.remotePeer.toString() === peerId.toString());
|
|
49
|
+
}
|
|
50
|
+
return this.connections;
|
|
8
51
|
}
|
|
9
|
-
|
|
10
|
-
|
|
52
|
+
async openConnection(peerId) {
|
|
53
|
+
if (this.components == null) {
|
|
54
|
+
throw errCode(new Error('Not initialized'), 'ERR_NOT_INITIALIZED');
|
|
55
|
+
}
|
|
56
|
+
const existingConnections = this.getConnections(peerId);
|
|
57
|
+
if (existingConnections.length > 0) {
|
|
58
|
+
return existingConnections[0];
|
|
59
|
+
}
|
|
60
|
+
const componentsB = mockNetwork.getNode(peerId);
|
|
61
|
+
const [aToB, bToA] = connectionPair(this.components, componentsB);
|
|
62
|
+
// track connections
|
|
63
|
+
this.connections.push(aToB);
|
|
64
|
+
componentsB.getConnectionManager().connections.push(bToA);
|
|
65
|
+
this.components.getConnectionManager().dispatchEvent(new CustomEvent('peer:connect', {
|
|
66
|
+
detail: aToB
|
|
67
|
+
}));
|
|
68
|
+
for (const protocol of this.components.getRegistrar().getProtocols()) {
|
|
69
|
+
for (const topology of this.components.getRegistrar().getTopologies(protocol)) {
|
|
70
|
+
topology.onConnect(componentsB.getPeerId(), aToB);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
componentsB.getConnectionManager().dispatchEvent(new CustomEvent('peer:connect', {
|
|
74
|
+
detail: bToA
|
|
75
|
+
}));
|
|
76
|
+
for (const protocol of componentsB.getRegistrar().getProtocols()) {
|
|
77
|
+
for (const topology of componentsB.getRegistrar().getTopologies(protocol)) {
|
|
78
|
+
topology.onConnect(this.components.getPeerId(), bToA);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return aToB;
|
|
11
82
|
}
|
|
12
|
-
|
|
13
|
-
|
|
83
|
+
async closeConnections(peerId) {
|
|
84
|
+
if (this.components == null) {
|
|
85
|
+
throw errCode(new Error('Not initialized'), 'ERR_NOT_INITIALIZED');
|
|
86
|
+
}
|
|
87
|
+
const connections = this.getConnections(peerId);
|
|
88
|
+
if (connections.length === 0) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const componentsB = mockNetwork.getNode(peerId);
|
|
92
|
+
for (const protocol of this.components.getRegistrar().getProtocols()) {
|
|
93
|
+
this.components.getRegistrar().getTopologies(protocol).forEach(topology => {
|
|
94
|
+
topology.onDisconnect(componentsB.getPeerId());
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
for (const conn of connections) {
|
|
98
|
+
await conn.close();
|
|
99
|
+
}
|
|
100
|
+
this.connections = this.connections.filter(c => !c.remotePeer.equals(peerId));
|
|
101
|
+
await componentsB.getConnectionManager().closeConnections(peerId);
|
|
14
102
|
}
|
|
15
103
|
}
|
|
16
104
|
export function mockConnectionManager() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.js","sourceRoot":"","sources":["../../../src/mocks/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"connection-manager.js","sourceRoot":"","sources":["../../../src/mocks/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAa,MAAM,oBAAoB,CAAA;AAKzE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,OAAO,MAAM,UAAU,CAAA;AAE9B,MAAM,WAAW;IAAjB;QACU,eAAU,GAAiB,EAAE,CAAA;IAmBvC,CAAC;IAjBC,OAAO,CAAE,UAAsB;QAC7B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAClC,CAAC;IAED,OAAO,CAAE,MAAc;QACrB,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,UAAU,EAAE;YACxC,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,EAAE;gBACzC,OAAO,UAAU,CAAA;aAClB;SACF;QAED,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,EAAE,oBAAoB,CAAC,CAAA;IAClE,CAAC;IAED,KAAK;QACH,IAAI,CAAC,UAAU,GAAG,EAAE,CAAA;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C,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;YAC3B,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,EAAE,qBAAqB,CAAC,CAAA;SACnE;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QAE/C,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,OAAM;SACP;QAED,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAE/C,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,YAAY,EAAE,EAAE;YACpE,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBACxE,QAAQ,CAAC,YAAY,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,CAAA;YAChD,CAAC,CAAC,CAAA;SACH;QAED,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;YAC9B,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;SACnB;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;QAE7E,MAAM,WAAW,CAAC,oBAAoB,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;IACnE,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,qBAAqB,EAAE,CAAA;AACpC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { mockConnectionGater } from './connection-gater.js';
|
|
2
|
-
export { mockConnectionManager } from './connection-manager.js';
|
|
2
|
+
export { mockConnectionManager, mockNetwork } from './connection-manager.js';
|
|
3
3
|
export { mockConnection, mockStream, connectionPair } from './connection.js';
|
|
4
4
|
export { mockMultiaddrConnection, mockMultiaddrConnPair } from './multiaddr-connection.js';
|
|
5
5
|
export { mockMuxer } from './muxer.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mocks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mocks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/src/mocks/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { mockConnectionGater } from './connection-gater.js';
|
|
2
|
-
export { mockConnectionManager } from './connection-manager.js';
|
|
2
|
+
export { mockConnectionManager, mockNetwork } from './connection-manager.js';
|
|
3
3
|
export { mockConnection, mockStream, connectionPair } from './connection.js';
|
|
4
4
|
export { mockMultiaddrConnection, mockMultiaddrConnPair } from './multiaddr-connection.js';
|
|
5
5
|
export { mockMuxer } from './muxer.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mocks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mocks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -2,7 +2,6 @@ import type { IncomingStreamData, Registrar, StreamHandler } from '@libp2p/inter
|
|
|
2
2
|
import type { Connection } from '@libp2p/interfaces/connection';
|
|
3
3
|
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
4
4
|
import type { Topology } from '@libp2p/interfaces/topology';
|
|
5
|
-
import type { Components } from '@libp2p/interfaces/src/components';
|
|
6
5
|
export declare class MockRegistrar implements Registrar {
|
|
7
6
|
private readonly topologies;
|
|
8
7
|
private readonly handlers;
|
|
@@ -16,5 +15,4 @@ export declare class MockRegistrar implements Registrar {
|
|
|
16
15
|
}
|
|
17
16
|
export declare function mockRegistrar(): MockRegistrar;
|
|
18
17
|
export declare function mockIncomingStreamEvent(protocol: string, conn: Connection, remotePeer: PeerId): Promise<IncomingStreamData>;
|
|
19
|
-
export declare function connectPeers(protocol: string, a: Components, b: Components): Promise<void>;
|
|
20
18
|
//# sourceMappingURL=registrar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../../src/mocks/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAChG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAE3D,
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../../src/mocks/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAChG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAE3D,qBAAa,aAAc,YAAW,SAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsE;IACjG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;IAEjE,YAAY;IAcN,MAAM,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5E,QAAQ,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAQ5C,UAAU,CAAE,QAAQ,EAAE,MAAM;IAUtB,QAAQ,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ;IAehE,UAAU,CAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;IAQjC,aAAa,CAAE,QAAQ,EAAE,MAAM;CAehC;AAED,wBAAgB,aAAa,kBAE5B;AAED,wBAAsB,uBAAuB,CAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAQlI"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { connectionPair } from './connection.js';
|
|
2
1
|
export class MockRegistrar {
|
|
3
2
|
constructor() {
|
|
4
3
|
this.topologies = new Map();
|
|
@@ -63,7 +62,7 @@ export class MockRegistrar {
|
|
|
63
62
|
if (output.length > 0) {
|
|
64
63
|
return output;
|
|
65
64
|
}
|
|
66
|
-
|
|
65
|
+
return [];
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
export function mockRegistrar() {
|
|
@@ -78,14 +77,4 @@ export async function mockIncomingStreamEvent(protocol, conn, remotePeer) {
|
|
|
78
77
|
}
|
|
79
78
|
};
|
|
80
79
|
}
|
|
81
|
-
export async function connectPeers(protocol, a, b) {
|
|
82
|
-
// Notify peers of connection
|
|
83
|
-
const [aToB, bToA] = connectionPair(a, b);
|
|
84
|
-
for (const topology of a.getRegistrar().getTopologies(protocol)) {
|
|
85
|
-
await topology.onConnect(b.getPeerId(), aToB);
|
|
86
|
-
}
|
|
87
|
-
for (const topology of b.getRegistrar().getTopologies(protocol)) {
|
|
88
|
-
await topology.onConnect(a.getPeerId(), bToA);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
80
|
//# sourceMappingURL=registrar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registrar.js","sourceRoot":"","sources":["../../../src/mocks/registrar.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registrar.js","sourceRoot":"","sources":["../../../src/mocks/registrar.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,aAAa;IA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,CAAC,CAAA;aACtB;SACF;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACrB,OAAO,MAAM,CAAA;SACd;QAED,OAAO,EAAE,CAAA;IACX,CAAC;CACF;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,IAAI,aAAa,EAAE,CAAA;AAC5B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAE,QAAgB,EAAE,IAAgB,EAAE,UAAkB;IACnG,OAAO;QACL,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC;QACnC,6CAA6C;QAC7C,UAAU,EAAE;YACV,UAAU;SACX;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/pubsub/api.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/pubsub/api.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;iCAUpB,UAAU,MAAM,EAAE,UAAU,CAAC;AAArD,wBAiGC"}
|
package/dist/src/pubsub/api.js
CHANGED
|
@@ -7,6 +7,7 @@ import delay from 'delay';
|
|
|
7
7
|
import { createComponents } from './utils.js';
|
|
8
8
|
import { start, stop } from '../index.js';
|
|
9
9
|
import { isStartable } from '@libp2p/interfaces';
|
|
10
|
+
import { mockNetwork } from '../mocks/connection-manager.js';
|
|
10
11
|
const topic = 'foo';
|
|
11
12
|
const data = uint8ArrayFromString('bar');
|
|
12
13
|
export default (common) => {
|
|
@@ -15,25 +16,27 @@ export default (common) => {
|
|
|
15
16
|
let components;
|
|
16
17
|
// Create pubsub router
|
|
17
18
|
beforeEach(async () => {
|
|
19
|
+
mockNetwork.reset();
|
|
18
20
|
components = await createComponents();
|
|
19
|
-
pubsub = await common.setup({
|
|
21
|
+
pubsub = components.setPubSub(await common.setup({
|
|
20
22
|
components,
|
|
21
23
|
init: {
|
|
22
24
|
emitSelf: true
|
|
23
25
|
}
|
|
24
|
-
});
|
|
26
|
+
}));
|
|
25
27
|
});
|
|
26
28
|
afterEach(async () => {
|
|
27
29
|
sinon.restore();
|
|
28
|
-
await stop(
|
|
30
|
+
await stop(common);
|
|
29
31
|
await common.teardown();
|
|
32
|
+
mockNetwork.reset();
|
|
30
33
|
});
|
|
31
34
|
it('can start correctly', async () => {
|
|
32
35
|
if (!isStartable(pubsub)) {
|
|
33
36
|
return;
|
|
34
37
|
}
|
|
35
38
|
sinon.spy(components.getRegistrar(), 'register');
|
|
36
|
-
await
|
|
39
|
+
await start(components);
|
|
37
40
|
expect(pubsub.isStarted()).to.equal(true);
|
|
38
41
|
expect(components.getRegistrar().register).to.have.property('callCount', 1);
|
|
39
42
|
});
|
|
@@ -42,8 +45,8 @@ export default (common) => {
|
|
|
42
45
|
return;
|
|
43
46
|
}
|
|
44
47
|
sinon.spy(components.getRegistrar(), 'unregister');
|
|
45
|
-
await
|
|
46
|
-
await
|
|
48
|
+
await start(components);
|
|
49
|
+
await stop(components);
|
|
47
50
|
expect(pubsub.isStarted()).to.equal(false);
|
|
48
51
|
expect(components.getRegistrar().unregister).to.have.property('callCount', 1);
|
|
49
52
|
});
|
|
@@ -51,7 +54,7 @@ export default (common) => {
|
|
|
51
54
|
const handler = () => {
|
|
52
55
|
throw new Error('a message should not be received');
|
|
53
56
|
};
|
|
54
|
-
await start(
|
|
57
|
+
await start(components);
|
|
55
58
|
pubsub.subscribe(topic);
|
|
56
59
|
pubsub.addEventListener('message', handler);
|
|
57
60
|
await pWaitFor(() => {
|
|
@@ -65,11 +68,11 @@ export default (common) => {
|
|
|
65
68
|
await pubsub.publish(topic, data);
|
|
66
69
|
// handlers are called async
|
|
67
70
|
await delay(100);
|
|
68
|
-
await stop(
|
|
71
|
+
await stop(components);
|
|
69
72
|
});
|
|
70
73
|
it('can subscribe and publish correctly', async () => {
|
|
71
74
|
const defer = pDefer();
|
|
72
|
-
await start(
|
|
75
|
+
await start(components);
|
|
73
76
|
pubsub.subscribe(topic);
|
|
74
77
|
pubsub.addEventListener('message', (evt) => {
|
|
75
78
|
expect(evt).to.have.nested.property('detail.topic', topic);
|
|
@@ -78,7 +81,7 @@ export default (common) => {
|
|
|
78
81
|
});
|
|
79
82
|
await pubsub.publish(topic, data);
|
|
80
83
|
await defer.promise;
|
|
81
|
-
await stop(
|
|
84
|
+
await stop(components);
|
|
82
85
|
});
|
|
83
86
|
});
|
|
84
87
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/pubsub/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/pubsub/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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AK,CAAC,OAAO,EAAE,CAAA;YACjB,CAAC,CAAC,CAAA;YACF,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACjC,MAAM,KAAK,CAAC,OAAO,CAAA;YAEnB,MAAM,IAAI,CAAC,UAAU,CAAC,CAAA;QACxB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-handlers.d.ts","sourceRoot":"","sources":["../../../src/pubsub/connection-handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection-handlers.d.ts","sourceRoot":"","sources":["../../../src/pubsub/connection-handlers.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAW,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;iCAOpB,UAAU,MAAM,EAAE,UAAU,CAAC;AAArD,wBA6YC"}
|
|
@@ -4,10 +4,10 @@ import pDefer from 'p-defer';
|
|
|
4
4
|
import pWaitFor from 'p-wait-for';
|
|
5
5
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
6
6
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
7
|
-
import { connectPeers } from '../mocks/registrar.js';
|
|
8
7
|
import { start, stop } from '../index.js';
|
|
9
8
|
import { createComponents } from './utils.js';
|
|
10
9
|
import { pEvent } from 'p-event';
|
|
10
|
+
import { mockNetwork } from '../mocks/connection-manager.js';
|
|
11
11
|
export default (common) => {
|
|
12
12
|
describe('pubsub connection handlers', () => {
|
|
13
13
|
let psA;
|
|
@@ -17,23 +17,22 @@ export default (common) => {
|
|
|
17
17
|
describe('nodes send state on connection', () => {
|
|
18
18
|
// Create pubsub nodes and connect them
|
|
19
19
|
beforeEach(async () => {
|
|
20
|
+
mockNetwork.reset();
|
|
20
21
|
componentsA = await createComponents();
|
|
21
22
|
componentsB = await createComponents();
|
|
22
|
-
psA = await common.setup({
|
|
23
|
+
psA = componentsA.setPubSub(await common.setup({
|
|
23
24
|
components: componentsA,
|
|
24
25
|
init: {}
|
|
25
|
-
});
|
|
26
|
-
psB = await common.setup({
|
|
26
|
+
}));
|
|
27
|
+
psB = componentsB.setPubSub(await common.setup({
|
|
27
28
|
components: componentsB,
|
|
28
29
|
init: {}
|
|
29
|
-
});
|
|
30
|
+
}));
|
|
30
31
|
// Start pubsub
|
|
31
|
-
await start(
|
|
32
|
+
await start(componentsA, componentsB);
|
|
32
33
|
expect(psA.getPeers()).to.be.empty();
|
|
33
34
|
expect(psB.getPeers()).to.be.empty();
|
|
34
|
-
|
|
35
|
-
// Make subscriptions prior to nodes connected
|
|
36
|
-
beforeEach(() => {
|
|
35
|
+
// Make subscriptions prior to nodes connected
|
|
37
36
|
psA.subscribe('Za');
|
|
38
37
|
psB.subscribe('Zb');
|
|
39
38
|
expect(psA.getPeers()).to.be.empty();
|
|
@@ -43,15 +42,16 @@ export default (common) => {
|
|
|
43
42
|
});
|
|
44
43
|
afterEach(async () => {
|
|
45
44
|
sinon.restore();
|
|
46
|
-
await stop(
|
|
45
|
+
await stop(componentsA, componentsB);
|
|
47
46
|
await common.teardown();
|
|
47
|
+
mockNetwork.reset();
|
|
48
48
|
});
|
|
49
49
|
it('existing subscriptions are sent upon peer connection', async function () {
|
|
50
50
|
const subscriptionsChanged = Promise.all([
|
|
51
51
|
pEvent(psA, 'subscription-change'),
|
|
52
52
|
pEvent(psB, 'subscription-change')
|
|
53
53
|
]);
|
|
54
|
-
await
|
|
54
|
+
await componentsA.getConnectionManager().openConnection(componentsB.getPeerId());
|
|
55
55
|
await subscriptionsChanged;
|
|
56
56
|
expect(psA.getPeers()).to.have.lengthOf(1);
|
|
57
57
|
expect(psB.getPeers()).to.have.lengthOf(1);
|
|
@@ -68,25 +68,27 @@ export default (common) => {
|
|
|
68
68
|
let componentsB;
|
|
69
69
|
// Create pubsub nodes and start them
|
|
70
70
|
beforeEach(async () => {
|
|
71
|
+
mockNetwork.reset();
|
|
71
72
|
componentsA = await createComponents();
|
|
72
73
|
componentsB = await createComponents();
|
|
73
|
-
psA = await common.setup({
|
|
74
|
+
psA = componentsA.setPubSub(await common.setup({
|
|
74
75
|
components: componentsA,
|
|
75
76
|
init: {}
|
|
76
|
-
});
|
|
77
|
-
psB = await common.setup({
|
|
77
|
+
}));
|
|
78
|
+
psB = componentsB.setPubSub(await common.setup({
|
|
78
79
|
components: componentsB,
|
|
79
80
|
init: {}
|
|
80
|
-
});
|
|
81
|
-
await start(
|
|
81
|
+
}));
|
|
82
|
+
await start(componentsA, componentsB);
|
|
82
83
|
});
|
|
83
84
|
afterEach(async () => {
|
|
84
85
|
sinon.restore();
|
|
85
|
-
await stop(
|
|
86
|
+
await stop(componentsA, componentsB);
|
|
86
87
|
await common.teardown();
|
|
88
|
+
mockNetwork.reset();
|
|
87
89
|
});
|
|
88
90
|
it('should get notified of connected peers on dial', async () => {
|
|
89
|
-
await
|
|
91
|
+
await componentsA.getConnectionManager().openConnection(componentsB.getPeerId());
|
|
90
92
|
return await Promise.all([
|
|
91
93
|
pWaitFor(() => psA.getPeers().length === 1),
|
|
92
94
|
pWaitFor(() => psB.getPeers().length === 1)
|
|
@@ -96,7 +98,7 @@ export default (common) => {
|
|
|
96
98
|
const defer = pDefer();
|
|
97
99
|
const topic = 'test-topic';
|
|
98
100
|
const data = uint8ArrayFromString('hey!');
|
|
99
|
-
await
|
|
101
|
+
await componentsA.getConnectionManager().openConnection(componentsB.getPeerId());
|
|
100
102
|
let subscribedTopics = psA.getTopics();
|
|
101
103
|
expect(subscribedTopics).to.not.include(topic);
|
|
102
104
|
psA.subscribe(topic);
|
|
@@ -126,25 +128,27 @@ export default (common) => {
|
|
|
126
128
|
let componentsB;
|
|
127
129
|
// Create pubsub nodes
|
|
128
130
|
beforeEach(async () => {
|
|
131
|
+
mockNetwork.reset();
|
|
129
132
|
componentsA = await createComponents();
|
|
130
133
|
componentsB = await createComponents();
|
|
131
|
-
psA = await common.setup({
|
|
134
|
+
psA = componentsA.setPubSub(await common.setup({
|
|
132
135
|
components: componentsA,
|
|
133
136
|
init: {}
|
|
134
|
-
});
|
|
135
|
-
psB = await common.setup({
|
|
137
|
+
}));
|
|
138
|
+
psB = componentsB.setPubSub(await common.setup({
|
|
136
139
|
components: componentsB,
|
|
137
140
|
init: {}
|
|
138
|
-
});
|
|
141
|
+
}));
|
|
139
142
|
});
|
|
140
143
|
afterEach(async () => {
|
|
141
144
|
sinon.restore();
|
|
142
|
-
await stop(
|
|
145
|
+
await stop(componentsA, componentsB);
|
|
143
146
|
await common.teardown();
|
|
147
|
+
mockNetwork.reset();
|
|
144
148
|
});
|
|
145
149
|
it('should get notified of connected peers after starting', async () => {
|
|
146
|
-
await start(
|
|
147
|
-
await
|
|
150
|
+
await start(componentsA, componentsB);
|
|
151
|
+
await componentsA.getConnectionManager().openConnection(componentsB.getPeerId());
|
|
148
152
|
return await Promise.all([
|
|
149
153
|
pWaitFor(() => psA.getPeers().length === 1),
|
|
150
154
|
pWaitFor(() => psB.getPeers().length === 1)
|
|
@@ -154,8 +158,8 @@ export default (common) => {
|
|
|
154
158
|
const defer = pDefer();
|
|
155
159
|
const topic = 'test-topic';
|
|
156
160
|
const data = uint8ArrayFromString('hey!');
|
|
157
|
-
await start(
|
|
158
|
-
await
|
|
161
|
+
await start(componentsA, componentsB);
|
|
162
|
+
await componentsA.getConnectionManager().openConnection(componentsB.getPeerId());
|
|
159
163
|
await Promise.all([
|
|
160
164
|
pWaitFor(() => psA.getPeers().length === 1),
|
|
161
165
|
pWaitFor(() => psB.getPeers().length === 1)
|
|
@@ -189,22 +193,24 @@ export default (common) => {
|
|
|
189
193
|
let componentsB;
|
|
190
194
|
// Create pubsub nodes and start them
|
|
191
195
|
beforeEach(async () => {
|
|
196
|
+
mockNetwork.reset();
|
|
192
197
|
componentsA = await createComponents();
|
|
193
198
|
componentsB = await createComponents();
|
|
194
|
-
psA = await common.setup({
|
|
199
|
+
psA = componentsA.setPubSub(await common.setup({
|
|
195
200
|
components: componentsA,
|
|
196
201
|
init: {}
|
|
197
|
-
});
|
|
198
|
-
psB = await common.setup({
|
|
202
|
+
}));
|
|
203
|
+
psB = componentsB.setPubSub(await common.setup({
|
|
199
204
|
components: componentsB,
|
|
200
205
|
init: {}
|
|
201
|
-
});
|
|
202
|
-
await start(
|
|
206
|
+
}));
|
|
207
|
+
await start(componentsA, componentsB);
|
|
203
208
|
});
|
|
204
209
|
afterEach(async () => {
|
|
205
210
|
sinon.restore();
|
|
206
|
-
await stop(
|
|
211
|
+
await stop(componentsA, componentsB);
|
|
207
212
|
await common.teardown();
|
|
213
|
+
mockNetwork.reset();
|
|
208
214
|
});
|
|
209
215
|
it.skip('should receive pubsub messages after a node restart', async function () {
|
|
210
216
|
const topic = 'test-topic';
|
|
@@ -212,7 +218,7 @@ export default (common) => {
|
|
|
212
218
|
let counter = 0;
|
|
213
219
|
const defer1 = pDefer();
|
|
214
220
|
const defer2 = pDefer();
|
|
215
|
-
await
|
|
221
|
+
await componentsA.getConnectionManager().openConnection(componentsB.getPeerId());
|
|
216
222
|
let subscribedTopics = psA.getTopics();
|
|
217
223
|
expect(subscribedTopics).to.not.include(topic);
|
|
218
224
|
psA.subscribe(topic);
|
|
@@ -243,7 +249,7 @@ export default (common) => {
|
|
|
243
249
|
return aHasConnectionToB != null && bHasConnectionToA != null;
|
|
244
250
|
});
|
|
245
251
|
await start(psB);
|
|
246
|
-
await
|
|
252
|
+
await componentsA.getConnectionManager().openConnection(componentsB.getPeerId());
|
|
247
253
|
// wait for remoteLibp2p to know about libp2p subscription
|
|
248
254
|
await pWaitFor(() => {
|
|
249
255
|
const subscribedPeers = psB.getSubscribers(topic);
|
|
@@ -293,7 +299,7 @@ export default (common) => {
|
|
|
293
299
|
// @ts-expect-error protected fields
|
|
294
300
|
const originalConnection = await psA._libp2p.dialer.connectToPeer(psB.peerId);
|
|
295
301
|
// second connection
|
|
296
|
-
await
|
|
302
|
+
await componentsA.getConnectionManager().openConnection(componentsB.getPeerId());
|
|
297
303
|
// Wait for subscriptions to occur
|
|
298
304
|
await pWaitFor(() => {
|
|
299
305
|
return psA.getSubscribers(topic).map(p => p.toString()).includes(componentsB.getPeerId().toString()) &&
|