@libp2p/pubsub 1.0.3 → 1.0.4

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.
Files changed (38) hide show
  1. package/package.json +86 -70
  2. package/dist/test/emit-self.spec.d.ts +0 -2
  3. package/dist/test/emit-self.spec.d.ts.map +0 -1
  4. package/dist/test/emit-self.spec.js +0 -63
  5. package/dist/test/emit-self.spec.js.map +0 -1
  6. package/dist/test/instance.spec.d.ts +0 -2
  7. package/dist/test/instance.spec.d.ts.map +0 -1
  8. package/dist/test/instance.spec.js +0 -50
  9. package/dist/test/instance.spec.js.map +0 -1
  10. package/dist/test/lifesycle.spec.d.ts +0 -2
  11. package/dist/test/lifesycle.spec.d.ts.map +0 -1
  12. package/dist/test/lifesycle.spec.js +0 -192
  13. package/dist/test/lifesycle.spec.js.map +0 -1
  14. package/dist/test/message.spec.d.ts +0 -2
  15. package/dist/test/message.spec.d.ts.map +0 -1
  16. package/dist/test/message.spec.js +0 -83
  17. package/dist/test/message.spec.js.map +0 -1
  18. package/dist/test/pubsub.spec.d.ts +0 -2
  19. package/dist/test/pubsub.spec.d.ts.map +0 -1
  20. package/dist/test/pubsub.spec.js +0 -310
  21. package/dist/test/pubsub.spec.js.map +0 -1
  22. package/dist/test/sign.spec.d.ts +0 -2
  23. package/dist/test/sign.spec.d.ts.map +0 -1
  24. package/dist/test/sign.spec.js +0 -93
  25. package/dist/test/sign.spec.js.map +0 -1
  26. package/dist/test/topic-validators.spec.d.ts +0 -2
  27. package/dist/test/topic-validators.spec.d.ts.map +0 -1
  28. package/dist/test/topic-validators.spec.js +0 -86
  29. package/dist/test/topic-validators.spec.js.map +0 -1
  30. package/dist/test/utils/index.d.ts +0 -23
  31. package/dist/test/utils/index.d.ts.map +0 -1
  32. package/dist/test/utils/index.js +0 -85
  33. package/dist/test/utils/index.js.map +0 -1
  34. package/dist/test/utils.spec.d.ts +0 -2
  35. package/dist/test/utils.spec.d.ts.map +0 -1
  36. package/dist/test/utils.spec.js +0 -53
  37. package/dist/test/utils.spec.js.map +0 -1
  38. package/dist/tsconfig.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,86 +1,48 @@
1
1
  {
2
2
  "name": "@libp2p/pubsub",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "libp2p pubsub base class",
5
- "type": "module",
6
- "files": [
7
- "src",
8
- "dist"
5
+ "license": "Apache-2.0 OR MIT",
6
+ "homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-pubsub#readme",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/libp2p/js-libp2p-interfaces.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/libp2p/js-libp2p-interfaces/issues"
13
+ },
14
+ "keywords": [
15
+ "interface",
16
+ "libp2p"
9
17
  ],
10
- "types": "dist/src/index.d.ts",
18
+ "engines": {
19
+ "node": ">=16.0.0",
20
+ "npm": ">=7.0.0"
21
+ },
22
+ "type": "module",
23
+ "types": "./dist/src/index.d.ts",
11
24
  "typesVersions": {
12
25
  "*": {
13
26
  "*": [
27
+ "*",
28
+ "dist/*",
29
+ "dist/src/*",
30
+ "dist/src/*/index"
31
+ ],
32
+ "src/*": [
33
+ "*",
34
+ "dist/*",
14
35
  "dist/src/*",
15
36
  "dist/src/*/index"
16
37
  ]
17
38
  }
18
39
  },
19
- "eslintConfig": {
20
- "extends": "ipfs",
21
- "ignorePatterns": [
22
- "src/message/*.d.ts",
23
- "src/message/*.js"
24
- ]
25
- },
26
- "scripts": {
27
- "lint": "aegir lint",
28
- "dep-check": "aegir dep-check dist/src/**/*.js",
29
- "build": "tsc",
30
- "postbuild": "npm run build:copy-proto-files",
31
- "pretest": "npm run build",
32
- "test": "aegir test -f ./dist/test/**/*.js",
33
- "test:chrome": "npm run test -- -t browser",
34
- "test:chrome-webworker": "npm run test -- -t webworker",
35
- "test:firefox": "npm run test -- -t browser -- --browser firefox",
36
- "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
37
- "test:node": "npm run test -- -t node --cov",
38
- "test:electron-main": "npm run test -- -t electron-main",
39
- "build:proto": "npm run build:proto:rpc && npm run build:proto:topic-descriptor",
40
- "build:proto:rpc": "pbjs -t static-module -w es6 -r libp2p-pubsub-rpc --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/rpc.js ./src/message/rpc.proto",
41
- "build:proto:topic-descriptor": "pbjs -t static-module -w es6 -r libp2p-pubsub-topic-descriptor --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/topic-descriptor.js ./src/message/topic-descriptor.proto",
42
- "build:proto-types": "npm run build:proto-types:rpc && npm run build:proto-types:topic-descriptor",
43
- "build:proto-types:rpc": "pbts -o src/message/rpc.d.ts src/message/rpc.js",
44
- "build:proto-types:topic-descriptor": "pbts -o src/message/topic-descriptor.d.ts src/message/topic-descriptor.js",
45
- "build:copy-proto-files": "cp src/message/*.js dist/src/message && cp src/message/*.d.ts dist/src/message"
46
- },
47
- "repository": {
48
- "type": "git",
49
- "url": "git+https://github.com/libp2p/js-libp2p-interfaces.git"
50
- },
51
- "keywords": [
52
- "libp2p",
53
- "interface"
40
+ "files": [
41
+ "src",
42
+ "dist/src",
43
+ "!dist/test",
44
+ "!**/*.tsbuildinfo"
54
45
  ],
55
- "author": "",
56
- "license": "Apache-2.0 OR MIT",
57
- "bugs": {
58
- "url": "https://github.com/libp2p/js-libp2p-interfaces/issues"
59
- },
60
- "homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-pubsub#readme",
61
- "dependencies": {
62
- "@libp2p/crypto": "^0.22.2",
63
- "@libp2p/interfaces": "^1.0.0",
64
- "@libp2p/peer-id": "^1.0.0",
65
- "@libp2p/peer-id-factory": "^1.0.0",
66
- "@libp2p/topology": "^1.0.0",
67
- "@multiformats/multiaddr": "^10.1.1",
68
- "debug": "^4.3.2",
69
- "err-code": "^3.0.1",
70
- "iso-random-stream": "^2.0.0",
71
- "it-length-prefixed": "^6.0.1",
72
- "it-pipe": "^2.0.2",
73
- "multiformats": "^9.4.10",
74
- "p-queue": "^7.1.0",
75
- "uint8arrays": "^3.0.0"
76
- },
77
- "devDependencies": {
78
- "@types/bl": "^5.0.2",
79
- "@types/debug": "^4.1.7",
80
- "aegir": "^36.1.3",
81
- "protobufjs": "^6.10.2",
82
- "util": "^0.12.4"
83
- },
84
46
  "exports": {
85
47
  ".": {
86
48
  "import": "./dist/src/index.js",
@@ -111,6 +73,16 @@
111
73
  "types": "./dist/src/message/topic-descriptor.d.ts"
112
74
  }
113
75
  },
76
+ "eslintConfig": {
77
+ "extends": "ipfs",
78
+ "parserOptions": {
79
+ "sourceType": "module"
80
+ },
81
+ "ignorePatterns": [
82
+ "src/message/*.d.ts",
83
+ "src/message/*.js"
84
+ ]
85
+ },
114
86
  "release": {
115
87
  "branches": [
116
88
  "master"
@@ -191,5 +163,49 @@
191
163
  "@semantic-release/github",
192
164
  "@semantic-release/git"
193
165
  ]
166
+ },
167
+ "scripts": {
168
+ "lint": "aegir lint",
169
+ "dep-check": "aegir dep-check dist/src/**/*.js",
170
+ "build": "tsc",
171
+ "postbuild": "npm run build:copy-proto-files",
172
+ "pretest": "npm run build",
173
+ "test": "aegir test -f ./dist/test/**/*.js",
174
+ "test:chrome": "npm run test -- -t browser",
175
+ "test:chrome-webworker": "npm run test -- -t webworker",
176
+ "test:firefox": "npm run test -- -t browser -- --browser firefox",
177
+ "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
178
+ "test:node": "npm run test -- -t node --cov",
179
+ "test:electron-main": "npm run test -- -t electron-main",
180
+ "build:proto": "npm run build:proto:rpc && npm run build:proto:topic-descriptor",
181
+ "build:proto:rpc": "pbjs -t static-module -w es6 -r libp2p-pubsub-rpc --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/rpc.js ./src/message/rpc.proto",
182
+ "build:proto:topic-descriptor": "pbjs -t static-module -w es6 -r libp2p-pubsub-topic-descriptor --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/topic-descriptor.js ./src/message/topic-descriptor.proto",
183
+ "build:proto-types": "npm run build:proto-types:rpc && npm run build:proto-types:topic-descriptor",
184
+ "build:proto-types:rpc": "pbts -o src/message/rpc.d.ts src/message/rpc.js",
185
+ "build:proto-types:topic-descriptor": "pbts -o src/message/topic-descriptor.d.ts src/message/topic-descriptor.js",
186
+ "build:copy-proto-files": "cp src/message/*.js dist/src/message && cp src/message/*.d.ts dist/src/message"
187
+ },
188
+ "dependencies": {
189
+ "@libp2p/crypto": "^0.22.2",
190
+ "@libp2p/interfaces": "^1.0.0",
191
+ "@libp2p/peer-id": "^1.0.0",
192
+ "@libp2p/peer-id-factory": "^1.0.0",
193
+ "@libp2p/topology": "^1.0.0",
194
+ "@multiformats/multiaddr": "^10.1.1",
195
+ "debug": "^4.3.2",
196
+ "err-code": "^3.0.1",
197
+ "iso-random-stream": "^2.0.0",
198
+ "it-length-prefixed": "^6.0.1",
199
+ "it-pipe": "^2.0.2",
200
+ "multiformats": "^9.4.10",
201
+ "p-queue": "^7.1.0",
202
+ "uint8arrays": "^3.0.0"
203
+ },
204
+ "devDependencies": {
205
+ "@types/bl": "^5.0.2",
206
+ "@types/debug": "^4.1.7",
207
+ "aegir": "^36.1.3",
208
+ "protobufjs": "^6.10.2",
209
+ "util": "^0.12.4"
194
210
  }
195
211
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=emit-self.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"emit-self.spec.d.ts","sourceRoot":"","sources":["../../test/emit-self.spec.ts"],"names":[],"mappings":""}
@@ -1,63 +0,0 @@
1
- import { expect } from 'aegir/utils/chai.js';
2
- import { createPeerId, mockRegistrar, PubsubImplementation } from './utils/index.js';
3
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
4
- import delay from 'delay';
5
- const protocol = '/pubsub/1.0.0';
6
- const topic = 'foo';
7
- const data = uint8ArrayFromString('bar');
8
- const shouldNotHappen = () => expect.fail();
9
- describe('emitSelf', () => {
10
- let pubsub;
11
- describe('enabled', () => {
12
- before(async () => {
13
- const peerId = await createPeerId();
14
- pubsub = new PubsubImplementation({
15
- multicodecs: [protocol],
16
- libp2p: {
17
- peerId,
18
- registrar: mockRegistrar
19
- },
20
- emitSelf: true
21
- });
22
- });
23
- before(async () => {
24
- await pubsub.start();
25
- pubsub.subscribe(topic);
26
- });
27
- after(async () => {
28
- await pubsub.stop();
29
- });
30
- it('should emit to self on publish', async () => {
31
- const promise = new Promise((resolve) => pubsub.once(topic, resolve));
32
- await pubsub.publish(topic, data);
33
- return await promise;
34
- });
35
- });
36
- describe('disabled', () => {
37
- before(async () => {
38
- const peerId = await createPeerId();
39
- pubsub = new PubsubImplementation({
40
- multicodecs: [protocol],
41
- libp2p: {
42
- peerId,
43
- registrar: mockRegistrar
44
- },
45
- emitSelf: false
46
- });
47
- });
48
- before(async () => {
49
- await pubsub.start();
50
- pubsub.subscribe(topic);
51
- });
52
- after(async () => {
53
- await pubsub.stop();
54
- });
55
- it('should not emit to self on publish', async () => {
56
- pubsub.once(topic, () => shouldNotHappen);
57
- await pubsub.publish(topic, data);
58
- // Wait 1 second to guarantee that self is not noticed
59
- await delay(1000);
60
- });
61
- });
62
- });
63
- //# sourceMappingURL=emit-self.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"emit-self.spec.js","sourceRoot":"","sources":["../../test/emit-self.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,QAAQ,GAA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,IAAI,EAAE;YAChB,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAA;YAEnC,MAAM,GAAG,IAAI,oBAAoB,CAAC;gBAChC,WAAW,EAAE,CAAC,QAAQ,CAAC;gBACvB,MAAM,EAAE;oBACN,MAAM;oBACN,SAAS,EAAE,aAAa;iBACzB;gBACD,QAAQ,EAAE,KAAK;aAChB,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;YACpB,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QACzB,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QACrB,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;YAClD,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,CAAA;YAEzC,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YAEjC,sDAAsD;YACtD,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA;QACnB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=instance.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instance.spec.d.ts","sourceRoot":"","sources":["../../test/instance.spec.ts"],"names":[],"mappings":""}
@@ -1,50 +0,0 @@
1
- import { expect } from 'aegir/utils/chai.js';
2
- import { PubsubBaseProtocol } from '../src/index.js';
3
- import { createPeerId, mockRegistrar } from './utils/index.js';
4
- class PubsubProtocol extends PubsubBaseProtocol {
5
- async _publish(message) {
6
- throw new Error('Method not implemented.');
7
- }
8
- }
9
- describe('pubsub instance', () => {
10
- let peerId;
11
- before(async () => {
12
- peerId = await createPeerId();
13
- });
14
- it('should throw if no debugName is provided', () => {
15
- expect(() => {
16
- // @ts-expect-error incorrect constructor args
17
- new PubsubProtocol(); // eslint-disable-line no-new
18
- }).to.throw();
19
- });
20
- it('should throw if no multicodec is provided', () => {
21
- expect(() => {
22
- // @ts-expect-error incorrect constructor args
23
- new PubsubProtocol({
24
- debugName: 'pubsub'
25
- });
26
- }).to.throw();
27
- });
28
- it('should throw if no libp2p is provided', () => {
29
- expect(() => {
30
- // @ts-expect-error incorrect constructor args
31
- new PubsubProtocol({
32
- debugName: 'pubsub',
33
- multicodecs: ['/pubsub/1.0.0']
34
- });
35
- }).to.throw();
36
- });
37
- it('should accept valid parameters', () => {
38
- expect(() => {
39
- new PubsubProtocol({
40
- debugName: 'pubsub',
41
- multicodecs: ['/pubsub/1.0.0'],
42
- libp2p: {
43
- peerId: peerId,
44
- registrar: mockRegistrar
45
- }
46
- });
47
- }).not.to.throw();
48
- });
49
- });
50
- //# sourceMappingURL=instance.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instance.spec.js","sourceRoot":"","sources":["../../test/instance.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EACL,YAAY,EACZ,aAAa,EACd,MAAM,kBAAkB,CAAA;AAIzB,MAAM,cAAe,SAAQ,kBAAkB;IAC7C,KAAK,CAAC,QAAQ,CAAE,OAAgB;QAC9B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;CACF;AAED,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,MAAc,CAAA;IAElB,MAAM,CAAC,KAAK,IAAI,EAAE;QAChB,MAAM,GAAG,MAAM,YAAY,EAAE,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,CAAC,GAAG,EAAE;YACV,8CAA8C;YAC9C,IAAI,cAAc,EAAE,CAAA,CAAC,6BAA6B;QACpD,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,GAAG,EAAE;YACV,8CAA8C;YAC9C,IAAI,cAAc,CAAC;gBACjB,SAAS,EAAE,QAAQ;aACpB,CAAC,CAAA;QACJ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,CAAC,GAAG,EAAE;YACV,8CAA8C;YAC9C,IAAI,cAAc,CAAC;gBACjB,SAAS,EAAE,QAAQ;gBACnB,WAAW,EAAE,CAAC,eAAe,CAAC;aAC/B,CAAC,CAAA;QACJ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,CAAC,GAAG,EAAE;YACV,IAAI,cAAc,CAAC;gBACjB,SAAS,EAAE,QAAQ;gBACnB,WAAW,EAAE,CAAC,eAAe,CAAC;gBAC9B,MAAM,EAAE;oBACN,MAAM,EAAE,MAAM;oBACd,SAAS,EAAE,aAAa;iBACzB;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=lifesycle.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lifesycle.spec.d.ts","sourceRoot":"","sources":["../../test/lifesycle.spec.ts"],"names":[],"mappings":""}
@@ -1,192 +0,0 @@
1
- import { expect } from 'aegir/utils/chai.js';
2
- import sinon from 'sinon';
3
- import { PubsubBaseProtocol } from '../src/index.js';
4
- import { createPeerId, createMockRegistrar, PubsubImplementation, ConnectionPair } from './utils/index.js';
5
- class PubsubProtocol extends PubsubBaseProtocol {
6
- async _publish(message) {
7
- throw new Error('Method not implemented.');
8
- }
9
- }
10
- describe('pubsub base lifecycle', () => {
11
- describe('should start and stop properly', () => {
12
- let pubsub;
13
- let sinonMockRegistrar;
14
- beforeEach(async () => {
15
- const peerId = await createPeerId();
16
- sinonMockRegistrar = {
17
- handle: sinon.stub(),
18
- register: sinon.stub().returns(`id-${Math.random()}`),
19
- unregister: sinon.stub()
20
- };
21
- pubsub = new PubsubProtocol({
22
- debugName: 'pubsub',
23
- multicodecs: ['/pubsub/1.0.0'],
24
- libp2p: {
25
- peerId: peerId,
26
- registrar: sinonMockRegistrar
27
- }
28
- });
29
- expect(pubsub.peers.size).to.be.eql(0);
30
- });
31
- afterEach(() => {
32
- sinon.restore();
33
- });
34
- it('should be able to start and stop', async () => {
35
- await pubsub.start();
36
- expect(sinonMockRegistrar.handle).to.have.property('calledOnce', true);
37
- expect(sinonMockRegistrar.register).to.have.property('calledOnce', true);
38
- await pubsub.stop();
39
- expect(sinonMockRegistrar.unregister).to.have.property('calledOnce', true);
40
- });
41
- it('starting should not throw if already started', async () => {
42
- await pubsub.start();
43
- await pubsub.start();
44
- expect(sinonMockRegistrar.handle).to.have.property('calledOnce', true);
45
- expect(sinonMockRegistrar.register).to.have.property('calledOnce', true);
46
- await pubsub.stop();
47
- expect(sinonMockRegistrar.unregister).to.have.property('calledOnce', true);
48
- });
49
- it('stopping should not throw if not started', async () => {
50
- await pubsub.stop();
51
- expect(sinonMockRegistrar.register).to.have.property('calledOnce', false);
52
- expect(sinonMockRegistrar.unregister).to.have.property('calledOnce', false);
53
- });
54
- });
55
- describe('should be able to register two nodes', () => {
56
- const protocol = '/pubsub/1.0.0';
57
- let pubsubA, pubsubB;
58
- let peerIdA, peerIdB;
59
- const registrarRecordA = new Map();
60
- const registrarRecordB = new Map();
61
- // mount pubsub
62
- beforeEach(async () => {
63
- peerIdA = await createPeerId();
64
- peerIdB = await createPeerId();
65
- pubsubA = new PubsubImplementation({
66
- multicodecs: [protocol],
67
- libp2p: {
68
- peerId: peerIdA,
69
- registrar: createMockRegistrar(registrarRecordA)
70
- }
71
- });
72
- pubsubB = new PubsubImplementation({
73
- multicodecs: [protocol],
74
- libp2p: {
75
- peerId: peerIdB,
76
- registrar: createMockRegistrar(registrarRecordB)
77
- }
78
- });
79
- });
80
- // start pubsub
81
- beforeEach(() => {
82
- pubsubA.start();
83
- pubsubB.start();
84
- expect(registrarRecordA).to.have.lengthOf(1);
85
- expect(registrarRecordB).to.have.lengthOf(1);
86
- });
87
- afterEach(async () => {
88
- sinon.restore();
89
- return await Promise.all([
90
- pubsubA.stop(),
91
- pubsubB.stop()
92
- ]);
93
- });
94
- it('should handle onConnect as expected', async () => {
95
- const onConnectA = registrarRecordA.get(protocol).onConnect;
96
- const handlerB = registrarRecordB.get(protocol).handler;
97
- // Notice peers of connection
98
- const [c0, c1] = ConnectionPair();
99
- await onConnectA(peerIdB, c0);
100
- await handlerB({
101
- protocol,
102
- stream: c1.stream,
103
- connection: {
104
- remotePeer: peerIdA
105
- }
106
- });
107
- expect(pubsubA.peers.size).to.be.eql(1);
108
- expect(pubsubB.peers.size).to.be.eql(1);
109
- });
110
- it('should use the latest connection if onConnect is called more than once', async () => {
111
- const onConnectA = registrarRecordA.get(protocol).onConnect;
112
- const handlerB = registrarRecordB.get(protocol).handler;
113
- // Notice peers of connection
114
- const [c0, c1] = ConnectionPair();
115
- const [c2] = ConnectionPair();
116
- sinon.spy(c0, 'newStream');
117
- await onConnectA(peerIdB, c0);
118
- await handlerB({
119
- protocol,
120
- stream: c1.stream,
121
- connection: {
122
- remotePeer: peerIdA
123
- }
124
- });
125
- expect(c0.newStream).to.have.property('callCount', 1);
126
- // @ts-expect-error _removePeer is a protected method
127
- sinon.spy(pubsubA, '_removePeer');
128
- sinon.spy(c2, 'newStream');
129
- await onConnectA(peerIdB, c2);
130
- expect(c2.newStream).to.have.property('callCount', 1);
131
- // @ts-expect-error _removePeer is a protected method
132
- expect(pubsubA._removePeer).to.have.property('callCount', 0);
133
- // Verify the first stream was closed
134
- // @ts-expect-error .returnValues is a sinon property
135
- const { stream: firstStream } = await c0.newStream.returnValues[0];
136
- try {
137
- await firstStream.sink(['test']);
138
- }
139
- catch (err) {
140
- expect(err).to.exist();
141
- return;
142
- }
143
- expect.fail('original stream should have ended');
144
- });
145
- it('should handle newStream errors in onConnect', async () => {
146
- const onConnectA = registrarRecordA.get(protocol).onConnect;
147
- const handlerB = registrarRecordB.get(protocol).handler;
148
- // Notice peers of connection
149
- const [c0, c1] = ConnectionPair();
150
- const error = new Error('new stream error');
151
- sinon.stub(c0, 'newStream').throws(error);
152
- await onConnectA(peerIdB, c0);
153
- await handlerB({
154
- protocol,
155
- stream: c1.stream,
156
- connection: {
157
- remotePeer: peerIdA
158
- }
159
- });
160
- expect(c0.newStream).to.have.property('callCount', 1);
161
- });
162
- it('should handle onDisconnect as expected', async () => {
163
- const onConnectA = registrarRecordA.get(protocol).onConnect;
164
- const onDisconnectA = registrarRecordA.get(protocol).onDisconnect;
165
- const handlerB = registrarRecordB.get(protocol).handler;
166
- const onDisconnectB = registrarRecordB.get(protocol).onDisconnect;
167
- // Notice peers of connection
168
- const [c0, c1] = ConnectionPair();
169
- await onConnectA(peerIdB, c0);
170
- await handlerB({
171
- protocol,
172
- stream: c1.stream,
173
- connection: {
174
- remotePeer: peerIdA
175
- }
176
- });
177
- // Notice peers of disconnect
178
- onDisconnectA(peerIdB);
179
- onDisconnectB(peerIdA);
180
- expect(pubsubA.peers.size).to.be.eql(0);
181
- expect(pubsubB.peers.size).to.be.eql(0);
182
- });
183
- it('should handle onDisconnect for unknown peers', () => {
184
- const onDisconnectA = registrarRecordA.get(protocol).onDisconnect;
185
- expect(pubsubA.peers.size).to.be.eql(0);
186
- // Notice peers of disconnect
187
- onDisconnectA(peerIdB);
188
- expect(pubsubA.peers.size).to.be.eql(0);
189
- });
190
- });
191
- });
192
- //# sourceMappingURL=lifesycle.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lifesycle.spec.js","sourceRoot":"","sources":["../../test/lifesycle.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACf,MAAM,kBAAkB,CAAA;AAKzB,MAAM,cAAe,SAAQ,kBAAkB;IAC7C,KAAK,CAAC,QAAQ,CAAE,OAAgB;QAC9B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;CACF;AAED,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;QAC9C,IAAI,MAAsB,CAAA;QAC1B,IAAI,kBAAsC,CAAA;QAE1C,UAAU,CAAC,KAAK,IAAI,EAAE;YACpB,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAA;YACnC,kBAAkB,GAAG;gBACnB,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE;gBACpB,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;gBACrD,UAAU,EAAE,KAAK,CAAC,IAAI,EAAE;aACzB,CAAA;YAED,MAAM,GAAG,IAAI,cAAc,CAAC;gBAC1B,SAAS,EAAE,QAAQ;gBACnB,WAAW,EAAE,CAAC,eAAe,CAAC;gBAC9B,MAAM,EAAE;oBACN,MAAM,EAAE,MAAM;oBACd,SAAS,EA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,CAAC,CAAC,CAAC,CAAA;YAEvC,6BAA6B;YAC7B,aAAa,CAAC,OAAO,CAAC,CAAA;YAEtB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=message.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.spec.d.ts","sourceRoot":"","sources":["../../test/message.spec.ts"],"names":[],"mappings":""}
@@ -1,83 +0,0 @@
1
- /* eslint-env mocha */
2
- import { expect } from 'aegir/utils/chai.js';
3
- import sinon from 'sinon';
4
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
5
- import { PubsubBaseProtocol } from '../src/index.js';
6
- import { createPeerId, mockRegistrar } from './utils/index.js';
7
- class PubsubProtocol extends PubsubBaseProtocol {
8
- async _publish(message) {
9
- throw new Error('Method not implemented');
10
- }
11
- async buildMessage(message) {
12
- return await this._buildMessage(message);
13
- }
14
- }
15
- describe('pubsub base messages', () => {
16
- let peerId;
17
- let pubsub;
18
- before(async () => {
19
- peerId = await createPeerId();
20
- pubsub = new PubsubProtocol({
21
- debugName: 'pubsub',
22
- multicodecs: ['/pubsub/1.0.0'],
23
- libp2p: {
24
- peerId: peerId,
25
- registrar: mockRegistrar
26
- }
27
- });
28
- });
29
- afterEach(() => {
30
- sinon.restore();
31
- });
32
- it('_buildMessage normalizes and signs messages', async () => {
33
- const message = {
34
- from: peerId.multihash.bytes,
35
- receivedFrom: peerId.toString(),
36
- data: uint8ArrayFromString('hello'),
37
- topicIDs: ['test-topic']
38
- };
39
- const signedMessage = await pubsub.buildMessage(message);
40
- await expect(pubsub.validate(signedMessage)).to.eventually.not.be.rejected();
41
- });
42
- it('validate with StrictNoSign will reject a message with from, signature, key, seqno present', async () => {
43
- const message = {
44
- from: peerId.multihash.bytes,
45
- receivedFrom: peerId.toString(),
46
- data: uint8ArrayFromString('hello'),
47
- topicIDs: ['test-topic']
48
- };
49
- sinon.stub(pubsub, 'globalSignaturePolicy').value('StrictSign');
50
- const signedMessage = await pubsub.buildMessage(message);
51
- sinon.stub(pubsub, 'globalSignaturePolicy').value('StrictNoSign');
52
- await expect(pubsub.validate(signedMessage)).to.eventually.be.rejected();
53
- delete signedMessage.from;
54
- await expect(pubsub.validate(signedMessage)).to.eventually.be.rejected();
55
- delete signedMessage.signature;
56
- await expect(pubsub.validate(signedMessage)).to.eventually.be.rejected();
57
- delete signedMessage.key;
58
- await expect(pubsub.validate(signedMessage)).to.eventually.be.rejected();
59
- delete signedMessage.seqno;
60
- await expect(pubsub.validate(signedMessage)).to.eventually.not.be.rejected();
61
- });
62
- it('validate with StrictNoSign will validate a message without a signature, key, and seqno', async () => {
63
- const message = {
64
- from: peerId.multihash.bytes,
65
- receivedFrom: peerId.toString(),
66
- data: uint8ArrayFromString('hello'),
67
- topicIDs: ['test-topic']
68
- };
69
- sinon.stub(pubsub, 'globalSignaturePolicy').value('StrictNoSign');
70
- const signedMessage = await pubsub.buildMessage(message);
71
- await expect(pubsub.validate(signedMessage)).to.eventually.not.be.rejected();
72
- });
73
- it('validate with StrictSign requires a signature', async () => {
74
- const message = {
75
- from: peerId.multihash.bytes,
76
- receivedFrom: peerId.toString(),
77
- data: uint8ArrayFromString('hello'),
78
- topicIDs: ['test-topic']
79
- };
80
- await expect(pubsub.validate(message)).to.be.rejectedWith(Error, 'Signing required and no signature was present');
81
- });
82
- });
83
- //# sourceMappingURL=message.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.spec.js","sourceRoot":"","sources":["../../test/message.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,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