@libp2p/floodsub 1.0.0 → 1.0.3

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.
@@ -1,10 +1,10 @@
1
- import { PubsubBaseProtocol } from '@libp2p/pubsub';
1
+ import { PubSubBaseProtocol } from '@libp2p/pubsub';
2
2
  import { multicodec } from './config.js';
3
3
  import { SimpleTimeCache } from './cache.js';
4
- import type { PubSub, PubSubEvents, PubSubOptions, Message } from '@libp2p/interfaces/pubsub';
4
+ import type { PubSub, PubSubInit, Message, PubSubRPC, PubSubRPCMessage } from '@libp2p/interfaces/pubsub';
5
5
  import type { PeerId } from '@libp2p/interfaces/peer-id';
6
6
  export { multicodec };
7
- export interface FloodSubOptions extends PubSubOptions {
7
+ export interface FloodSubInit extends PubSubInit {
8
8
  seenTTL?: number;
9
9
  }
10
10
  /**
@@ -12,9 +12,19 @@ export interface FloodSubOptions extends PubSubOptions {
12
12
  * delivering an API for Publish/Subscribe, but with no CastTree Forming
13
13
  * (it just floods the network).
14
14
  */
15
- export declare class FloodSub<EventMap extends PubSubEvents = PubSubEvents> extends PubsubBaseProtocol<EventMap> implements PubSub<EventMap & PubSubEvents> {
15
+ export declare class FloodSub extends PubSubBaseProtocol implements PubSub {
16
16
  seenCache: SimpleTimeCache<boolean>;
17
- constructor(options: FloodSubOptions);
17
+ constructor(init?: FloodSubInit);
18
+ /**
19
+ * Decode a Uint8Array into an RPC object
20
+ */
21
+ decodeRpc(bytes: Uint8Array): PubSubRPC;
22
+ /**
23
+ * Encode an RPC object into a Uint8Array
24
+ */
25
+ encodeRpc(rpc: PubSubRPC): Uint8Array;
26
+ decodeMessage(bytes: Uint8Array): PubSubRPCMessage;
27
+ encodeMessage(rpc: PubSubRPCMessage): Uint8Array;
18
28
  /**
19
29
  * Process incoming message
20
30
  * Extends base implementation to check router cache.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":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MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,kBAAmB,YAAW,MAAM;IACzD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;gBAE7B,IAAI,CAAC,EAAE,YAAY;IAiBhC;;OAEG;IACH,SAAS,CAAE,KAAK,EAAE,UAAU,GAAG,SAAS;IAIxC;;OAEG;IACH,SAAS,CAAE,GAAG,EAAE,SAAS,GAAG,UAAU;IAItC,aAAa,CAAE,KAAK,EAAE,UAAU,GAAG,gBAAgB;IAInD,aAAa,CAAE,GAAG,EAAE,gBAAgB,GAAG,UAAU;IAIjD;;;OAGG;IACG,cAAc,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAcpD;;OAEG;IACG,cAAc,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;CAwBrD"}
package/dist/src/index.js CHANGED
@@ -1,19 +1,20 @@
1
1
  import { toString } from 'uint8arrays/to-string';
2
- import { PubsubBaseProtocol } from '@libp2p/pubsub';
2
+ import { PubSubBaseProtocol } from '@libp2p/pubsub';
3
3
  import { multicodec } from './config.js';
4
4
  import { SimpleTimeCache } from './cache.js';
5
- const debugName = 'libp2p:floodsub';
5
+ import { logger } from '@libp2p/logger';
6
+ import { RPC } from './message/rpc.js';
7
+ const log = logger('libp2p:floodsub');
6
8
  export { multicodec };
7
9
  /**
8
10
  * FloodSub (aka dumbsub is an implementation of pubsub focused on
9
11
  * delivering an API for Publish/Subscribe, but with no CastTree Forming
10
12
  * (it just floods the network).
11
13
  */
12
- export class FloodSub extends PubsubBaseProtocol {
13
- constructor(options) {
14
+ export class FloodSub extends PubSubBaseProtocol {
15
+ constructor(init) {
14
16
  super({
15
- ...options,
16
- debugName: debugName,
17
+ ...init,
17
18
  canRelayMessage: true,
18
19
  multicodecs: [multicodec]
19
20
  });
@@ -23,9 +24,27 @@ export class FloodSub extends PubsubBaseProtocol {
23
24
  * @type {TimeCache}
24
25
  */
25
26
  this.seenCache = new SimpleTimeCache({
26
- validityMs: options.seenTTL ?? 30000
27
+ validityMs: init?.seenTTL ?? 30000
27
28
  });
28
29
  }
30
+ /**
31
+ * Decode a Uint8Array into an RPC object
32
+ */
33
+ decodeRpc(bytes) {
34
+ return RPC.decode(bytes);
35
+ }
36
+ /**
37
+ * Encode an RPC object into a Uint8Array
38
+ */
39
+ encodeRpc(rpc) {
40
+ return RPC.encode(rpc);
41
+ }
42
+ decodeMessage(bytes) {
43
+ return RPC.Message.decode(bytes);
44
+ }
45
+ encodeMessage(rpc) {
46
+ return RPC.Message.encode(rpc);
47
+ }
29
48
  /**
30
49
  * Process incoming message
31
50
  * Extends base implementation to check router cache.
@@ -46,19 +65,19 @@ export class FloodSub extends PubsubBaseProtocol {
46
65
  async publishMessage(from, message) {
47
66
  const peers = this.getSubscribers(message.topic);
48
67
  if (peers == null || peers.length === 0) {
49
- this.log('no peers are subscribed to topic %s', message.topic);
68
+ log('no peers are subscribed to topic %s', message.topic);
50
69
  return;
51
70
  }
52
71
  peers.forEach(id => {
53
- if (this.peerId.equals(id)) {
54
- this.log('not sending message on topic %s to myself', message.topic);
72
+ if (this.components.getPeerId().equals(id)) {
73
+ log('not sending message on topic %s to myself', message.topic);
55
74
  return;
56
75
  }
57
76
  if (id.equals(from)) {
58
- this.log('not sending message on topic %s to sender %p', message.topic, id);
77
+ log('not sending message on topic %s to sender %p', message.topic, id);
59
78
  return;
60
79
  }
61
- this.log('publish msgs on topics %s %p', message.topic, id);
80
+ log('publish msgs on topics %s %p', message.topic, id);
62
81
  this.send(id, { messages: [message] });
63
82
  });
64
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB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AEhD,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACvC,GAAG,CAAC,qCAAqC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;YACzD,OAAM;SACP;QAED,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;YACjB,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;gBAC1C,GAAG,CAAC,2CAA2C,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;gBAC/D,OAAM;aACP;YAED,IAAI,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;gBACnB,GAAG,CAAC,8CAA8C,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;gBACtE,OAAM;aACP;YAED,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;YAEtD,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,88 @@
1
+ export interface RPC {
2
+ subscriptions: RPC.SubOpts[];
3
+ messages: RPC.Message[];
4
+ control?: ControlMessage;
5
+ }
6
+ export declare namespace RPC {
7
+ interface SubOpts {
8
+ subscribe?: boolean;
9
+ topic?: string;
10
+ }
11
+ namespace SubOpts {
12
+ const codec: () => import("protons-runtime/dist/src/codecs/codec").Codec<SubOpts>;
13
+ const encode: (obj: SubOpts) => Uint8Array;
14
+ const decode: (buf: Uint8Array) => SubOpts;
15
+ }
16
+ interface Message {
17
+ from?: Uint8Array;
18
+ data?: Uint8Array;
19
+ sequenceNumber?: Uint8Array;
20
+ topic?: string;
21
+ signature?: Uint8Array;
22
+ key?: Uint8Array;
23
+ }
24
+ namespace Message {
25
+ const codec: () => import("protons-runtime/dist/src/codecs/codec").Codec<Message>;
26
+ const encode: (obj: Message) => Uint8Array;
27
+ const decode: (buf: Uint8Array) => Message;
28
+ }
29
+ const codec: () => import("protons-runtime/dist/src/codecs/codec").Codec<RPC>;
30
+ const encode: (obj: RPC) => Uint8Array;
31
+ const decode: (buf: Uint8Array) => RPC;
32
+ }
33
+ export interface ControlMessage {
34
+ ihave: ControlIHave[];
35
+ iwant: ControlIWant[];
36
+ graft: ControlGraft[];
37
+ prune: ControlPrune[];
38
+ }
39
+ export declare namespace ControlMessage {
40
+ const codec: () => import("protons-runtime/dist/src/codecs/codec").Codec<ControlMessage>;
41
+ const encode: (obj: ControlMessage) => Uint8Array;
42
+ const decode: (buf: Uint8Array) => ControlMessage;
43
+ }
44
+ export interface ControlIHave {
45
+ topic?: string;
46
+ messageIDs: Uint8Array[];
47
+ }
48
+ export declare namespace ControlIHave {
49
+ const codec: () => import("protons-runtime/dist/src/codecs/codec").Codec<ControlIHave>;
50
+ const encode: (obj: ControlIHave) => Uint8Array;
51
+ const decode: (buf: Uint8Array) => ControlIHave;
52
+ }
53
+ export interface ControlIWant {
54
+ messageIDs: Uint8Array[];
55
+ }
56
+ export declare namespace ControlIWant {
57
+ const codec: () => import("protons-runtime/dist/src/codecs/codec").Codec<ControlIWant>;
58
+ const encode: (obj: ControlIWant) => Uint8Array;
59
+ const decode: (buf: Uint8Array) => ControlIWant;
60
+ }
61
+ export interface ControlGraft {
62
+ topic?: string;
63
+ }
64
+ export declare namespace ControlGraft {
65
+ const codec: () => import("protons-runtime/dist/src/codecs/codec").Codec<ControlGraft>;
66
+ const encode: (obj: ControlGraft) => Uint8Array;
67
+ const decode: (buf: Uint8Array) => ControlGraft;
68
+ }
69
+ export interface ControlPrune {
70
+ topic?: string;
71
+ peers: PeerInfo[];
72
+ backoff?: bigint;
73
+ }
74
+ export declare namespace ControlPrune {
75
+ const codec: () => import("protons-runtime/dist/src/codecs/codec").Codec<ControlPrune>;
76
+ const encode: (obj: ControlPrune) => Uint8Array;
77
+ const decode: (buf: Uint8Array) => ControlPrune;
78
+ }
79
+ export interface PeerInfo {
80
+ peerID?: Uint8Array;
81
+ signedPeerRecord?: Uint8Array;
82
+ }
83
+ export declare namespace PeerInfo {
84
+ const codec: () => import("protons-runtime/dist/src/codecs/codec").Codec<PeerInfo>;
85
+ const encode: (obj: PeerInfo) => Uint8Array;
86
+ const decode: (buf: Uint8Array) => PeerInfo;
87
+ }
88
+ //# sourceMappingURL=rpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../../src/message/rpc.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,GAAG;IAClB,aAAa,EAAE,GAAG,CAAC,OAAO,EAAE,CAAA;IAC5B,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,CAAA;IACvB,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB;AAED,yBAAiB,GAAG,CAAC;IACnB,UAAiB,OAAO;QACtB,SAAS,CAAC,EAAE,OAAO,CAAA;QACnB,KAAK,CAAC,EAAE,MAAM,CAAA;KACf;IAED,UAAiB,OAAO,CAAC;QAChB,MAAM,KAAK,sEAKjB,CAAA;QAEM,MAAM,MAAM,QAAS,OAAO,KAAG,UAErC,CAAA;QAEM,MAAM,MAAM,QAAS,UAAU,KAAG,OAExC,CAAA;KACF;IACD,UAAiB,OAAO;QACtB,IAAI,CAAC,EAAE,UAAU,CAAA;QACjB,IAAI,CAAC,EAAE,UAAU,CAAA;QACjB,cAAc,CAAC,EAAE,UAAU,CAAA;QAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,SAAS,CAAC,EAAE,UAAU,CAAA;QACtB,GAAG,CAAC,EAAE,UAAU,CAAA;KACjB;IAED,UAAiB,OAAO,CAAC;QAChB,MAAM,KAAK,sEASjB,CAAA;QAEM,MAAM,MAAM,QAAS,OAAO,KAAG,UAErC,CAAA;QAEM,MAAM,MAAM,QAAS,UAAU,KAAG,OAExC,CAAA;KACF;IAEM,MAAM,KAAK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AK,EAAE,QAAQ,EAAE,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,yBAAiB,YAAY,CAAC;IACrB,MAAM,KAAK,2EAMjB,CAAA;IAEM,MAAM,MAAM,QAAS,YAAY,KAAG,UAE1C,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,YAExC,CAAA;CACF;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,UAAU,CAAA;CAC9B;AAED,yBAAiB,QAAQ,CAAC;IACjB,MAAM,KAAK,uEAKjB,CAAA;IAEM,MAAM,MAAM,QAAS,QAAQ,KAAG,UAEtC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,QAExC,CAAA;CACF"}
@@ -0,0 +1,145 @@
1
+ /* eslint-disable import/export */
2
+ /* eslint-disable @typescript-eslint/no-namespace */
3
+ import { encodeMessage, decodeMessage, message, bool, string, bytes, uint64 } from 'protons-runtime';
4
+ export var RPC;
5
+ (function (RPC) {
6
+ let SubOpts;
7
+ (function (SubOpts) {
8
+ SubOpts.codec = () => {
9
+ return message({
10
+ 1: { name: 'subscribe', codec: bool, optional: true },
11
+ 2: { name: 'topic', codec: string, optional: true }
12
+ });
13
+ };
14
+ SubOpts.encode = (obj) => {
15
+ return encodeMessage(obj, SubOpts.codec());
16
+ };
17
+ SubOpts.decode = (buf) => {
18
+ return decodeMessage(buf, SubOpts.codec());
19
+ };
20
+ })(SubOpts = RPC.SubOpts || (RPC.SubOpts = {}));
21
+ let Message;
22
+ (function (Message) {
23
+ Message.codec = () => {
24
+ return message({
25
+ 1: { name: 'from', codec: bytes, optional: true },
26
+ 2: { name: 'data', codec: bytes, optional: true },
27
+ 3: { name: 'sequenceNumber', codec: bytes, optional: true },
28
+ 4: { name: 'topic', codec: string, optional: true },
29
+ 5: { name: 'signature', codec: bytes, optional: true },
30
+ 6: { name: 'key', codec: bytes, optional: true }
31
+ });
32
+ };
33
+ Message.encode = (obj) => {
34
+ return encodeMessage(obj, Message.codec());
35
+ };
36
+ Message.decode = (buf) => {
37
+ return decodeMessage(buf, Message.codec());
38
+ };
39
+ })(Message = RPC.Message || (RPC.Message = {}));
40
+ RPC.codec = () => {
41
+ return message({
42
+ 1: { name: 'subscriptions', codec: RPC.SubOpts.codec(), repeats: true },
43
+ 2: { name: 'messages', codec: RPC.Message.codec(), repeats: true },
44
+ 3: { name: 'control', codec: ControlMessage.codec(), optional: true }
45
+ });
46
+ };
47
+ RPC.encode = (obj) => {
48
+ return encodeMessage(obj, RPC.codec());
49
+ };
50
+ RPC.decode = (buf) => {
51
+ return decodeMessage(buf, RPC.codec());
52
+ };
53
+ })(RPC || (RPC = {}));
54
+ export var ControlMessage;
55
+ (function (ControlMessage) {
56
+ ControlMessage.codec = () => {
57
+ return message({
58
+ 1: { name: 'ihave', codec: ControlIHave.codec(), repeats: true },
59
+ 2: { name: 'iwant', codec: ControlIWant.codec(), repeats: true },
60
+ 3: { name: 'graft', codec: ControlGraft.codec(), repeats: true },
61
+ 4: { name: 'prune', codec: ControlPrune.codec(), repeats: true }
62
+ });
63
+ };
64
+ ControlMessage.encode = (obj) => {
65
+ return encodeMessage(obj, ControlMessage.codec());
66
+ };
67
+ ControlMessage.decode = (buf) => {
68
+ return decodeMessage(buf, ControlMessage.codec());
69
+ };
70
+ })(ControlMessage || (ControlMessage = {}));
71
+ export var ControlIHave;
72
+ (function (ControlIHave) {
73
+ ControlIHave.codec = () => {
74
+ return message({
75
+ 1: { name: 'topic', codec: string, optional: true },
76
+ 2: { name: 'messageIDs', codec: bytes, repeats: true }
77
+ });
78
+ };
79
+ ControlIHave.encode = (obj) => {
80
+ return encodeMessage(obj, ControlIHave.codec());
81
+ };
82
+ ControlIHave.decode = (buf) => {
83
+ return decodeMessage(buf, ControlIHave.codec());
84
+ };
85
+ })(ControlIHave || (ControlIHave = {}));
86
+ export var ControlIWant;
87
+ (function (ControlIWant) {
88
+ ControlIWant.codec = () => {
89
+ return message({
90
+ 1: { name: 'messageIDs', codec: bytes, repeats: true }
91
+ });
92
+ };
93
+ ControlIWant.encode = (obj) => {
94
+ return encodeMessage(obj, ControlIWant.codec());
95
+ };
96
+ ControlIWant.decode = (buf) => {
97
+ return decodeMessage(buf, ControlIWant.codec());
98
+ };
99
+ })(ControlIWant || (ControlIWant = {}));
100
+ export var ControlGraft;
101
+ (function (ControlGraft) {
102
+ ControlGraft.codec = () => {
103
+ return message({
104
+ 1: { name: 'topic', codec: string, optional: true }
105
+ });
106
+ };
107
+ ControlGraft.encode = (obj) => {
108
+ return encodeMessage(obj, ControlGraft.codec());
109
+ };
110
+ ControlGraft.decode = (buf) => {
111
+ return decodeMessage(buf, ControlGraft.codec());
112
+ };
113
+ })(ControlGraft || (ControlGraft = {}));
114
+ export var ControlPrune;
115
+ (function (ControlPrune) {
116
+ ControlPrune.codec = () => {
117
+ return message({
118
+ 1: { name: 'topic', codec: string, optional: true },
119
+ 2: { name: 'peers', codec: PeerInfo.codec(), repeats: true },
120
+ 3: { name: 'backoff', codec: uint64, optional: true }
121
+ });
122
+ };
123
+ ControlPrune.encode = (obj) => {
124
+ return encodeMessage(obj, ControlPrune.codec());
125
+ };
126
+ ControlPrune.decode = (buf) => {
127
+ return decodeMessage(buf, ControlPrune.codec());
128
+ };
129
+ })(ControlPrune || (ControlPrune = {}));
130
+ export var PeerInfo;
131
+ (function (PeerInfo) {
132
+ PeerInfo.codec = () => {
133
+ return message({
134
+ 1: { name: 'peerID', codec: bytes, optional: true },
135
+ 2: { name: 'signedPeerRecord', codec: bytes, optional: true }
136
+ });
137
+ };
138
+ PeerInfo.encode = (obj) => {
139
+ return encodeMessage(obj, PeerInfo.codec());
140
+ };
141
+ PeerInfo.decode = (buf) => {
142
+ return decodeMessage(buf, PeerInfo.codec());
143
+ };
144
+ })(PeerInfo || (PeerInfo = {}));
145
+ //# sourceMappingURL=rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc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AY,KAAZ,YAAY,QAgB5B;AAOD,MAAM,KAAW,QAAQ,CAexB;AAfD,WAAiB,QAAQ;IACV,cAAK,GAAG,GAAG,EAAE;QACxB,OAAO,OAAO,CAAW;YACvB,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE;YACnD,CAAC,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC9D,CAAC,CAAA;IACJ,CAAC,CAAA;IAEY,eAAM,GAAG,CAAC,GAAa,EAAc,EAAE;QAClD,OAAO,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;IAEY,eAAM,GAAG,CAAC,GAAe,EAAY,EAAE;QAClD,OAAO,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;AACH,CAAC,EAfgB,QAAQ,KAAR,QAAQ,QAexB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/floodsub",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p-floodsub#readme",
@@ -40,7 +40,10 @@
40
40
  "extends": "ipfs",
41
41
  "parserOptions": {
42
42
  "sourceType": "module"
43
- }
43
+ },
44
+ "ignorePatterns": [
45
+ "*.d.ts"
46
+ ]
44
47
  },
45
48
  "release": {
46
49
  "branches": [
@@ -124,33 +127,37 @@
124
127
  ]
125
128
  },
126
129
  "scripts": {
130
+ "clean": "aegir clean",
127
131
  "lint": "aegir lint",
128
- "dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
129
- "build": "tsc",
130
- "pretest": "npm run build",
132
+ "dep-check": "aegir dep-check",
133
+ "build": "aegir build",
134
+ "generate": "protons ./src/message/rpc.proto",
131
135
  "test": "aegir test -f dist/test",
132
- "test:chrome": "npm run test -- -t browser --cov",
133
- "test:chrome-webworker": "npm run test -- -t webworker",
134
- "test:firefox": "npm run test -- -t browser -- --browser firefox",
135
- "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
136
- "test:node": "npm run test -- -t node --cov",
137
- "test:electron-main": "npm run test -- -t electron-main",
138
- "release": "semantic-release"
136
+ "test:chrome": "aegir test -t browser --cov",
137
+ "test:chrome-webworker": "aegir test -t webworker",
138
+ "test:firefox": "aegir test -t browser -- --browser firefox",
139
+ "test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
140
+ "test:node": "aegir test -t node --cov",
141
+ "test:electron-main": "aegir test -t electron-main",
142
+ "release": "aegir release"
139
143
  },
140
144
  "dependencies": {
141
- "@libp2p/interfaces": "^1.3.6",
142
- "@libp2p/logger": "^1.0.3",
143
- "@libp2p/pubsub": "^1.2.4",
145
+ "@libp2p/interfaces": "^1.3.20",
146
+ "@libp2p/logger": "^1.1.3",
147
+ "@libp2p/pubsub": "^1.2.14",
148
+ "protons-runtime": "^1.0.2",
144
149
  "uint8arrays": "^3.0.0"
145
150
  },
146
151
  "devDependencies": {
147
- "@libp2p/interface-compliance-tests": "^1.0.8",
148
- "@libp2p/peer-id": "^1.1.3",
149
- "@libp2p/peer-id-factory": "^1.0.5",
150
- "@multiformats/multiaddr": "^10.1.5",
151
- "aegir": "^36.1.1",
152
+ "@libp2p/interface-compliance-tests": "^1.1.21",
153
+ "@libp2p/peer-collections": "^1.0.1",
154
+ "@libp2p/peer-id": "^1.1.9",
155
+ "@libp2p/peer-id-factory": "^1.0.9",
156
+ "@multiformats/multiaddr": "^10.1.8",
157
+ "aegir": "^37.0.7",
152
158
  "multiformats": "^9.4.5",
153
159
  "p-wait-for": "^4.1.0",
160
+ "protons": "^3.0.2",
154
161
  "sinon": "^13.0.1",
155
162
  "wherearewe": "^1.0.0"
156
163
  }
package/src/index.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  import { toString } from 'uint8arrays/to-string'
2
- import { PubsubBaseProtocol } from '@libp2p/pubsub'
2
+ import { PubSubBaseProtocol } from '@libp2p/pubsub'
3
3
  import { multicodec } from './config.js'
4
4
  import { SimpleTimeCache } from './cache.js'
5
- import type { PubSub, PubSubEvents, PubSubOptions, Message } from '@libp2p/interfaces/pubsub'
5
+ import type { PubSub, PubSubInit, Message, PubSubRPC, PubSubRPCMessage } from '@libp2p/interfaces/pubsub'
6
6
  import type { PeerId } from '@libp2p/interfaces/peer-id'
7
+ import { logger } from '@libp2p/logger'
8
+ import { RPC } from './message/rpc.js'
7
9
 
8
- const debugName = 'libp2p:floodsub'
10
+ const log = logger('libp2p:floodsub')
9
11
 
10
12
  export { multicodec }
11
13
 
12
- export interface FloodSubOptions extends PubSubOptions {
14
+ export interface FloodSubInit extends PubSubInit {
13
15
  seenTTL?: number
14
16
  }
15
17
 
@@ -18,13 +20,12 @@ export interface FloodSubOptions extends PubSubOptions {
18
20
  * delivering an API for Publish/Subscribe, but with no CastTree Forming
19
21
  * (it just floods the network).
20
22
  */
21
- export class FloodSub <EventMap extends PubSubEvents = PubSubEvents> extends PubsubBaseProtocol<EventMap> implements PubSub<EventMap & PubSubEvents> {
23
+ export class FloodSub extends PubSubBaseProtocol implements PubSub {
22
24
  public seenCache: SimpleTimeCache<boolean>
23
25
 
24
- constructor (options: FloodSubOptions) {
26
+ constructor (init?: FloodSubInit) {
25
27
  super({
26
- ...options,
27
- debugName: debugName,
28
+ ...init,
28
29
  canRelayMessage: true,
29
30
  multicodecs: [multicodec]
30
31
  })
@@ -35,10 +36,32 @@ export class FloodSub <EventMap extends PubSubEvents = PubSubEvents> extends Pub
35
36
  * @type {TimeCache}
36
37
  */
37
38
  this.seenCache = new SimpleTimeCache<boolean>({
38
- validityMs: options.seenTTL ?? 30000
39
+ validityMs: init?.seenTTL ?? 30000
39
40
  })
40
41
  }
41
42
 
43
+ /**
44
+ * Decode a Uint8Array into an RPC object
45
+ */
46
+ decodeRpc (bytes: Uint8Array): PubSubRPC {
47
+ return RPC.decode(bytes)
48
+ }
49
+
50
+ /**
51
+ * Encode an RPC object into a Uint8Array
52
+ */
53
+ encodeRpc (rpc: PubSubRPC): Uint8Array {
54
+ return RPC.encode(rpc)
55
+ }
56
+
57
+ decodeMessage (bytes: Uint8Array): PubSubRPCMessage {
58
+ return RPC.Message.decode(bytes)
59
+ }
60
+
61
+ encodeMessage (rpc: PubSubRPCMessage): Uint8Array {
62
+ return RPC.Message.encode(rpc)
63
+ }
64
+
42
65
  /**
43
66
  * Process incoming message
44
67
  * Extends base implementation to check router cache.
@@ -64,22 +87,22 @@ export class FloodSub <EventMap extends PubSubEvents = PubSubEvents> extends Pub
64
87
  const peers = this.getSubscribers(message.topic)
65
88
 
66
89
  if (peers == null || peers.length === 0) {
67
- this.log('no peers are subscribed to topic %s', message.topic)
90
+ log('no peers are subscribed to topic %s', message.topic)
68
91
  return
69
92
  }
70
93
 
71
94
  peers.forEach(id => {
72
- if (this.peerId.equals(id)) {
73
- this.log('not sending message on topic %s to myself', message.topic)
95
+ if (this.components.getPeerId().equals(id)) {
96
+ log('not sending message on topic %s to myself', message.topic)
74
97
  return
75
98
  }
76
99
 
77
100
  if (id.equals(from)) {
78
- this.log('not sending message on topic %s to sender %p', message.topic, id)
101
+ log('not sending message on topic %s to sender %p', message.topic, id)
79
102
  return
80
103
  }
81
104
 
82
- this.log('publish msgs on topics %s %p', message.topic, id)
105
+ log('publish msgs on topics %s %p', message.topic, id)
83
106
 
84
107
  this.send(id, { messages: [message] })
85
108
  })
@@ -0,0 +1,52 @@
1
+ syntax = "proto3";
2
+
3
+ message RPC {
4
+ repeated SubOpts subscriptions = 1;
5
+ repeated Message messages = 2;
6
+ optional ControlMessage control = 3;
7
+
8
+ message SubOpts {
9
+ optional bool subscribe = 1; // subscribe or unsubcribe
10
+ optional string topic = 2;
11
+ }
12
+
13
+ message Message {
14
+ optional bytes from = 1;
15
+ optional bytes data = 2;
16
+ optional bytes sequenceNumber = 3;
17
+ optional string topic = 4;
18
+ optional bytes signature = 5;
19
+ optional bytes key = 6;
20
+ }
21
+ }
22
+
23
+ message ControlMessage {
24
+ repeated ControlIHave ihave = 1;
25
+ repeated ControlIWant iwant = 2;
26
+ repeated ControlGraft graft = 3;
27
+ repeated ControlPrune prune = 4;
28
+ }
29
+
30
+ message ControlIHave {
31
+ optional string topic = 1;
32
+ repeated bytes messageIDs = 2;
33
+ }
34
+
35
+ message ControlIWant {
36
+ repeated bytes messageIDs = 1;
37
+ }
38
+
39
+ message ControlGraft {
40
+ optional string topic = 1;
41
+ }
42
+
43
+ message ControlPrune {
44
+ optional string topic = 1;
45
+ repeated PeerInfo peers = 2;
46
+ optional uint64 backoff = 3;
47
+ }
48
+
49
+ message PeerInfo {
50
+ optional bytes peerID = 1;
51
+ optional bytes signedPeerRecord = 2;
52
+ }
@@ -0,0 +1,213 @@
1
+ /* eslint-disable import/export */
2
+ /* eslint-disable @typescript-eslint/no-namespace */
3
+
4
+ import { encodeMessage, decodeMessage, message, bool, string, bytes, uint64 } from 'protons-runtime'
5
+
6
+ export interface RPC {
7
+ subscriptions: RPC.SubOpts[]
8
+ messages: RPC.Message[]
9
+ control?: ControlMessage
10
+ }
11
+
12
+ export namespace RPC {
13
+ export interface SubOpts {
14
+ subscribe?: boolean
15
+ topic?: string
16
+ }
17
+
18
+ export namespace SubOpts {
19
+ export const codec = () => {
20
+ return message<SubOpts>({
21
+ 1: { name: 'subscribe', codec: bool, optional: true },
22
+ 2: { name: 'topic', codec: string, optional: true }
23
+ })
24
+ }
25
+
26
+ export const encode = (obj: SubOpts): Uint8Array => {
27
+ return encodeMessage(obj, SubOpts.codec())
28
+ }
29
+
30
+ export const decode = (buf: Uint8Array): SubOpts => {
31
+ return decodeMessage(buf, SubOpts.codec())
32
+ }
33
+ }
34
+ export interface Message {
35
+ from?: Uint8Array
36
+ data?: Uint8Array
37
+ sequenceNumber?: Uint8Array
38
+ topic?: string
39
+ signature?: Uint8Array
40
+ key?: Uint8Array
41
+ }
42
+
43
+ export namespace Message {
44
+ export const codec = () => {
45
+ return message<Message>({
46
+ 1: { name: 'from', codec: bytes, optional: true },
47
+ 2: { name: 'data', codec: bytes, optional: true },
48
+ 3: { name: 'sequenceNumber', codec: bytes, optional: true },
49
+ 4: { name: 'topic', codec: string, optional: true },
50
+ 5: { name: 'signature', codec: bytes, optional: true },
51
+ 6: { name: 'key', codec: bytes, optional: true }
52
+ })
53
+ }
54
+
55
+ export const encode = (obj: Message): Uint8Array => {
56
+ return encodeMessage(obj, Message.codec())
57
+ }
58
+
59
+ export const decode = (buf: Uint8Array): Message => {
60
+ return decodeMessage(buf, Message.codec())
61
+ }
62
+ }
63
+
64
+ export const codec = () => {
65
+ return message<RPC>({
66
+ 1: { name: 'subscriptions', codec: RPC.SubOpts.codec(), repeats: true },
67
+ 2: { name: 'messages', codec: RPC.Message.codec(), repeats: true },
68
+ 3: { name: 'control', codec: ControlMessage.codec(), optional: true }
69
+ })
70
+ }
71
+
72
+ export const encode = (obj: RPC): Uint8Array => {
73
+ return encodeMessage(obj, RPC.codec())
74
+ }
75
+
76
+ export const decode = (buf: Uint8Array): RPC => {
77
+ return decodeMessage(buf, RPC.codec())
78
+ }
79
+ }
80
+
81
+ export interface ControlMessage {
82
+ ihave: ControlIHave[]
83
+ iwant: ControlIWant[]
84
+ graft: ControlGraft[]
85
+ prune: ControlPrune[]
86
+ }
87
+
88
+ export namespace ControlMessage {
89
+ export const codec = () => {
90
+ return message<ControlMessage>({
91
+ 1: { name: 'ihave', codec: ControlIHave.codec(), repeats: true },
92
+ 2: { name: 'iwant', codec: ControlIWant.codec(), repeats: true },
93
+ 3: { name: 'graft', codec: ControlGraft.codec(), repeats: true },
94
+ 4: { name: 'prune', codec: ControlPrune.codec(), repeats: true }
95
+ })
96
+ }
97
+
98
+ export const encode = (obj: ControlMessage): Uint8Array => {
99
+ return encodeMessage(obj, ControlMessage.codec())
100
+ }
101
+
102
+ export const decode = (buf: Uint8Array): ControlMessage => {
103
+ return decodeMessage(buf, ControlMessage.codec())
104
+ }
105
+ }
106
+
107
+ export interface ControlIHave {
108
+ topic?: string
109
+ messageIDs: Uint8Array[]
110
+ }
111
+
112
+ export namespace ControlIHave {
113
+ export const codec = () => {
114
+ return message<ControlIHave>({
115
+ 1: { name: 'topic', codec: string, optional: true },
116
+ 2: { name: 'messageIDs', codec: bytes, repeats: true }
117
+ })
118
+ }
119
+
120
+ export const encode = (obj: ControlIHave): Uint8Array => {
121
+ return encodeMessage(obj, ControlIHave.codec())
122
+ }
123
+
124
+ export const decode = (buf: Uint8Array): ControlIHave => {
125
+ return decodeMessage(buf, ControlIHave.codec())
126
+ }
127
+ }
128
+
129
+ export interface ControlIWant {
130
+ messageIDs: Uint8Array[]
131
+ }
132
+
133
+ export namespace ControlIWant {
134
+ export const codec = () => {
135
+ return message<ControlIWant>({
136
+ 1: { name: 'messageIDs', codec: bytes, repeats: true }
137
+ })
138
+ }
139
+
140
+ export const encode = (obj: ControlIWant): Uint8Array => {
141
+ return encodeMessage(obj, ControlIWant.codec())
142
+ }
143
+
144
+ export const decode = (buf: Uint8Array): ControlIWant => {
145
+ return decodeMessage(buf, ControlIWant.codec())
146
+ }
147
+ }
148
+
149
+ export interface ControlGraft {
150
+ topic?: string
151
+ }
152
+
153
+ export namespace ControlGraft {
154
+ export const codec = () => {
155
+ return message<ControlGraft>({
156
+ 1: { name: 'topic', codec: string, optional: true }
157
+ })
158
+ }
159
+
160
+ export const encode = (obj: ControlGraft): Uint8Array => {
161
+ return encodeMessage(obj, ControlGraft.codec())
162
+ }
163
+
164
+ export const decode = (buf: Uint8Array): ControlGraft => {
165
+ return decodeMessage(buf, ControlGraft.codec())
166
+ }
167
+ }
168
+
169
+ export interface ControlPrune {
170
+ topic?: string
171
+ peers: PeerInfo[]
172
+ backoff?: bigint
173
+ }
174
+
175
+ export namespace ControlPrune {
176
+ export const codec = () => {
177
+ return message<ControlPrune>({
178
+ 1: { name: 'topic', codec: string, optional: true },
179
+ 2: { name: 'peers', codec: PeerInfo.codec(), repeats: true },
180
+ 3: { name: 'backoff', codec: uint64, optional: true }
181
+ })
182
+ }
183
+
184
+ export const encode = (obj: ControlPrune): Uint8Array => {
185
+ return encodeMessage(obj, ControlPrune.codec())
186
+ }
187
+
188
+ export const decode = (buf: Uint8Array): ControlPrune => {
189
+ return decodeMessage(buf, ControlPrune.codec())
190
+ }
191
+ }
192
+
193
+ export interface PeerInfo {
194
+ peerID?: Uint8Array
195
+ signedPeerRecord?: Uint8Array
196
+ }
197
+
198
+ export namespace PeerInfo {
199
+ export const codec = () => {
200
+ return message<PeerInfo>({
201
+ 1: { name: 'peerID', codec: bytes, optional: true },
202
+ 2: { name: 'signedPeerRecord', codec: bytes, optional: true }
203
+ })
204
+ }
205
+
206
+ export const encode = (obj: PeerInfo): Uint8Array => {
207
+ return encodeMessage(obj, PeerInfo.codec())
208
+ }
209
+
210
+ export const decode = (buf: Uint8Array): PeerInfo => {
211
+ return decodeMessage(buf, PeerInfo.codec())
212
+ }
213
+ }