@libp2p/pubsub 1.2.3 → 1.2.7
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/errors.d.ts +8 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +8 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +33 -30
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +192 -128
- package/dist/src/index.js.map +1 -1
- package/dist/src/message/rpc.d.ts +586 -175
- package/dist/src/message/rpc.js +1238 -67
- package/dist/src/message/sign.d.ts +1 -1
- package/dist/src/message/sign.d.ts.map +1 -1
- package/dist/src/message/sign.js +8 -14
- package/dist/src/message/sign.js.map +1 -1
- package/dist/src/peer-streams.d.ts +5 -5
- package/dist/src/peer-streams.d.ts.map +1 -1
- package/dist/src/peer-streams.js +1 -0
- package/dist/src/peer-streams.js.map +1 -1
- package/dist/src/utils.d.ts +6 -9
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +36 -35
- package/dist/src/utils.js.map +1 -1
- package/package.json +7 -10
- package/src/errors.ts +8 -0
- package/src/index.ts +236 -140
- package/src/message/rpc.d.ts +586 -175
- package/src/message/rpc.js +1238 -67
- package/src/message/rpc.proto +38 -4
- package/src/message/sign.ts +10 -16
- package/src/peer-streams.ts +6 -4
- package/src/utils.ts +35 -34
package/dist/src/errors.d.ts
CHANGED
@@ -15,10 +15,18 @@ export declare const codes: {
|
|
15
15
|
* Message expected to have a `seqno`, but doesn't
|
16
16
|
*/
|
17
17
|
ERR_MISSING_SEQNO: string;
|
18
|
+
/**
|
19
|
+
* Message expected to have a `key`, but doesn't
|
20
|
+
*/
|
21
|
+
ERR_MISSING_KEY: string;
|
18
22
|
/**
|
19
23
|
* Message `signature` is invalid
|
20
24
|
*/
|
21
25
|
ERR_INVALID_SIGNATURE: string;
|
26
|
+
/**
|
27
|
+
* Message expected to have a `from`, but doesn't
|
28
|
+
*/
|
29
|
+
ERR_MISSING_FROM: string;
|
22
30
|
/**
|
23
31
|
* Message expected to not have a `from`, but does
|
24
32
|
*/
|
package/dist/src/errors.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,KAAK;IAChB;;OAEG;;IAEH;;OAEG;;IAKH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAKH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;CAEJ,CAAA"}
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,KAAK;IAChB;;OAEG;;IAEH;;OAEG;;IAKH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAKH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;CAEJ,CAAA"}
|
package/dist/src/errors.js
CHANGED
@@ -16,10 +16,18 @@ export const codes = {
|
|
16
16
|
* Message expected to have a `seqno`, but doesn't
|
17
17
|
*/
|
18
18
|
ERR_MISSING_SEQNO: 'ERR_MISSING_SEQNO',
|
19
|
+
/**
|
20
|
+
* Message expected to have a `key`, but doesn't
|
21
|
+
*/
|
22
|
+
ERR_MISSING_KEY: 'ERR_MISSING_KEY',
|
19
23
|
/**
|
20
24
|
* Message `signature` is invalid
|
21
25
|
*/
|
22
26
|
ERR_INVALID_SIGNATURE: 'ERR_INVALID_SIGNATURE',
|
27
|
+
/**
|
28
|
+
* Message expected to have a `from`, but doesn't
|
29
|
+
*/
|
30
|
+
ERR_MISSING_FROM: 'ERR_MISSING_FROM',
|
23
31
|
// Strict no-signing codes
|
24
32
|
/**
|
25
33
|
* Message expected to not have a `from`, but does
|
package/dist/src/errors.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB;;OAEG;IACH,4BAA4B,EAAE,8BAA8B;IAC5D;;OAEG;IACH,8BAA8B,EAAE,gCAAgC;IAEhE,uBAAuB;IAEvB;;OAEG;IACH,qBAAqB,EAAE,uBAAuB;IAC9C;;OAEG;IACH,iBAAiB,EAAE,mBAAmB;IACtC;;OAEG;IACH,qBAAqB,EAAE,uBAAuB;
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB;;OAEG;IACH,4BAA4B,EAAE,8BAA8B;IAC5D;;OAEG;IACH,8BAA8B,EAAE,gCAAgC;IAEhE,uBAAuB;IAEvB;;OAEG;IACH,qBAAqB,EAAE,uBAAuB;IAC9C;;OAEG;IACH,iBAAiB,EAAE,mBAAmB;IACtC;;OAEG;IACH,eAAe,EAAE,iBAAiB;IAClC;;OAEG;IACH,qBAAqB,EAAE,uBAAuB;IAC9C;;OAEG;IACH,gBAAgB,EAAE,kBAAkB;IAEpC,0BAA0B;IAE1B;;OAEG;IACH,mBAAmB,EAAE,qBAAqB;IAC1C;;OAEG;IACH,wBAAwB,EAAE,0BAA0B;IACpD;;OAEG;IACH,kBAAkB,EAAE,oBAAoB;IACxC;;OAEG;IACH,oBAAoB,EAAE,sBAAsB;CAC7C,CAAA"}
|
package/dist/src/index.d.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
import { EventEmitter } from '@libp2p/interfaces';
|
1
|
+
import { EventEmitter, EventHandler } from '@libp2p/interfaces';
|
2
2
|
import Queue from 'p-queue';
|
3
|
-
import { RPC, IRPC } from './message/rpc.js';
|
4
|
-
import { PeerStreams } from './peer-streams.js';
|
5
3
|
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
6
4
|
import type { Registrar, IncomingStreamData } from '@libp2p/interfaces/registrar';
|
7
5
|
import type { Connection } from '@libp2p/interfaces/connection';
|
8
|
-
import type
|
9
|
-
import type { PubSub, Message, StrictNoSign, StrictSign, PubsubOptions, PubsubEvents } from '@libp2p/interfaces/pubsub';
|
6
|
+
import type { PubSub, Message, StrictNoSign, StrictSign, PubSubOptions, PubSubEvents, RPC, PeerStreams, RPCSubscription } from '@libp2p/interfaces/pubsub';
|
10
7
|
import type { Logger } from '@libp2p/logger';
|
8
|
+
import type { PeerMap } from '@libp2p/peer-map';
|
9
|
+
import type { IRPC } from './message/rpc.js';
|
10
|
+
import { RPC as RPCProto } from './message/rpc.js';
|
11
11
|
export interface TopicValidator {
|
12
12
|
(topic: string, message: Message): Promise<void>;
|
13
13
|
}
|
@@ -15,7 +15,7 @@ export interface TopicValidator {
|
|
15
15
|
* PubsubBaseProtocol handles the peers and connections logic for pubsub routers
|
16
16
|
* and specifies the API that pubsub routers should have.
|
17
17
|
*/
|
18
|
-
export declare abstract class PubsubBaseProtocol<EventMap> extends EventEmitter<EventMap &
|
18
|
+
export declare abstract class PubsubBaseProtocol<EventMap extends PubSubEvents = PubSubEvents> extends EventEmitter<EventMap & PubSubEvents> implements PubSub<EventMap & PubSubEvents> {
|
19
19
|
peerId: PeerId;
|
20
20
|
started: boolean;
|
21
21
|
/**
|
@@ -29,11 +29,11 @@ export declare abstract class PubsubBaseProtocol<EventMap> extends EventEmitter<
|
|
29
29
|
/**
|
30
30
|
* Map of peer streams
|
31
31
|
*/
|
32
|
-
peers:
|
32
|
+
peers: PeerMap<PeerStreams>;
|
33
33
|
/**
|
34
34
|
* The signature policy to follow by default
|
35
35
|
*/
|
36
|
-
globalSignaturePolicy: StrictNoSign | StrictSign;
|
36
|
+
globalSignaturePolicy: typeof StrictNoSign | typeof StrictSign;
|
37
37
|
/**
|
38
38
|
* If router can relay received messages, even if not subscribed
|
39
39
|
*/
|
@@ -51,12 +51,12 @@ export declare abstract class PubsubBaseProtocol<EventMap> extends EventEmitter<
|
|
51
51
|
topicValidators: Map<string, TopicValidator>;
|
52
52
|
queue: Queue;
|
53
53
|
registrar: Registrar;
|
54
|
+
multicodecs: string[];
|
54
55
|
protected log: Logger;
|
55
|
-
protected multicodecs: string[];
|
56
56
|
protected _libp2p: any;
|
57
57
|
private _registrarHandlerId;
|
58
58
|
private _registrarTopologyId;
|
59
|
-
constructor(props:
|
59
|
+
constructor(props: PubSubOptions);
|
60
60
|
/**
|
61
61
|
* Register the pubsub protocol onto the libp2p node.
|
62
62
|
*
|
@@ -83,7 +83,7 @@ export declare abstract class PubsubBaseProtocol<EventMap> extends EventEmitter<
|
|
83
83
|
/**
|
84
84
|
* Notifies the router that a peer has been connected
|
85
85
|
*/
|
86
|
-
|
86
|
+
addPeer(peerId: PeerId, protocol: string): PeerStreams;
|
87
87
|
/**
|
88
88
|
* Notifies the router that a peer has been disconnected
|
89
89
|
*/
|
@@ -91,23 +91,19 @@ export declare abstract class PubsubBaseProtocol<EventMap> extends EventEmitter<
|
|
91
91
|
/**
|
92
92
|
* Responsible for processing each RPC message received by other peers.
|
93
93
|
*/
|
94
|
-
|
94
|
+
processMessages(peerId: PeerId, stream: AsyncIterable<Uint8Array>, peerStreams: PeerStreams): Promise<void>;
|
95
95
|
/**
|
96
96
|
* Handles an rpc request from a peer
|
97
97
|
*/
|
98
|
-
|
98
|
+
processRpc(from: PeerId, peerStreams: PeerStreams, rpc: RPC): Promise<void>;
|
99
99
|
/**
|
100
100
|
* Handles a subscription change from a peer
|
101
101
|
*/
|
102
|
-
|
102
|
+
processRpcSubOpt(id: PeerId, subOpt: RPCSubscription): void;
|
103
103
|
/**
|
104
104
|
* Handles an message from a peer
|
105
105
|
*/
|
106
|
-
|
107
|
-
/**
|
108
|
-
* Emit a message from a peer
|
109
|
-
*/
|
110
|
-
_emitMessage(message: Message): void;
|
106
|
+
processMessage(from: PeerId, msg: Message): Promise<void>;
|
111
107
|
/**
|
112
108
|
* The default msgID implementation
|
113
109
|
* Child class can override this.
|
@@ -117,25 +113,29 @@ export declare abstract class PubsubBaseProtocol<EventMap> extends EventEmitter<
|
|
117
113
|
* Whether to accept a message from a peer
|
118
114
|
* Override to create a graylist
|
119
115
|
*/
|
120
|
-
|
116
|
+
acceptFrom(id: PeerId): boolean;
|
121
117
|
/**
|
122
118
|
* Decode Uint8Array into an RPC object.
|
123
119
|
* This can be override to use a custom router protobuf.
|
124
120
|
*/
|
125
|
-
|
121
|
+
decodeRpc(bytes: Uint8Array): RPCProto;
|
126
122
|
/**
|
127
123
|
* Encode RPC object into a Uint8Array.
|
128
124
|
* This can be override to use a custom router protobuf.
|
129
125
|
*/
|
130
|
-
|
126
|
+
encodeRpc(rpc: IRPC): Uint8Array;
|
131
127
|
/**
|
132
128
|
* Send an rpc object to a peer
|
133
129
|
*/
|
134
|
-
|
130
|
+
send(peer: PeerId, data: {
|
131
|
+
messages?: Message[];
|
132
|
+
subscriptions?: string[];
|
133
|
+
subscribe?: boolean;
|
134
|
+
}): void;
|
135
135
|
/**
|
136
|
-
* Send
|
136
|
+
* Send an rpc object to a peer
|
137
137
|
*/
|
138
|
-
|
138
|
+
sendRpc(peer: PeerId, rpc: IRPC): void;
|
139
139
|
/**
|
140
140
|
* Validates the given message. The signature will be checked for authenticity.
|
141
141
|
* Throws an error on invalid messages
|
@@ -145,31 +145,34 @@ export declare abstract class PubsubBaseProtocol<EventMap> extends EventEmitter<
|
|
145
145
|
* Normalizes the message and signs it, if signing is enabled.
|
146
146
|
* Should be used by the routers to create the message to send.
|
147
147
|
*/
|
148
|
-
|
148
|
+
buildMessage(message: Message): Promise<Message>;
|
149
149
|
/**
|
150
150
|
* Get a list of the peer-ids that are subscribed to one topic.
|
151
151
|
*/
|
152
|
-
getSubscribers(topic: string):
|
152
|
+
getSubscribers(topic: string): PeerId[];
|
153
153
|
/**
|
154
154
|
* Publishes messages to all subscribed peers
|
155
155
|
*/
|
156
|
-
|
156
|
+
dispatchEvent(event: CustomEvent): boolean;
|
157
157
|
/**
|
158
158
|
* Overriding the implementation of publish should handle the appropriate algorithms for the publish/subscriber implementation.
|
159
159
|
* For example, a Floodsub implementation might simply publish each message to each topic for every peer
|
160
160
|
*/
|
161
|
-
abstract
|
161
|
+
abstract publishMessage(peerId: PeerId, message: Message): Promise<void>;
|
162
162
|
/**
|
163
163
|
* Subscribes to a given topic.
|
164
164
|
*/
|
165
165
|
subscribe(topic: string): void;
|
166
166
|
/**
|
167
|
-
* Unsubscribe from the given topic
|
167
|
+
* Unsubscribe from the given topic
|
168
168
|
*/
|
169
169
|
unsubscribe(topic: string): void;
|
170
170
|
/**
|
171
171
|
* Get the list of topics which the peer is subscribed to.
|
172
172
|
*/
|
173
173
|
getTopics(): string[];
|
174
|
+
getPeers(): PeerId[];
|
175
|
+
addEventListener<U extends keyof EventMap>(type: U, callback: EventHandler<EventMap[U]>, options?: AddEventListenerOptions | boolean): void;
|
176
|
+
removeEventListener<U extends keyof EventMap>(type: U, callback: EventHandler<EventMap[U]> | undefined, options?: EventListenerOptions | boolean): void;
|
174
177
|
}
|
175
178
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAe,MAAM,oBAAoB,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAe,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAG5E,OAAO,KAAK,MAAM,SAAS,CAAA;AAS3B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EA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