@libp2p/gossipsub 14.1.1-6059227cb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/dist/index.min.js +19 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/config.d.ts +32 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/constants.d.ts +213 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +217 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.d.ts +9 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +15 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/gossipsub.d.ts +419 -0
- package/dist/src/gossipsub.d.ts.map +1 -0
- package/dist/src/gossipsub.js +2520 -0
- package/dist/src/gossipsub.js.map +1 -0
- package/dist/src/index.d.ts +344 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +43 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/message/decodeRpc.d.ts +11 -0
- package/dist/src/message/decodeRpc.d.ts.map +1 -0
- package/dist/src/message/decodeRpc.js +10 -0
- package/dist/src/message/decodeRpc.js.map +1 -0
- package/dist/src/message/index.d.ts +2 -0
- package/dist/src/message/index.d.ts.map +1 -0
- package/dist/src/message/index.js +2 -0
- package/dist/src/message/index.js.map +1 -0
- package/dist/src/message/rpc.d.ts +99 -0
- package/dist/src/message/rpc.d.ts.map +1 -0
- package/dist/src/message/rpc.js +663 -0
- package/dist/src/message/rpc.js.map +1 -0
- package/dist/src/message-cache.d.ts +80 -0
- package/dist/src/message-cache.d.ts.map +1 -0
- package/dist/src/message-cache.js +144 -0
- package/dist/src/message-cache.js.map +1 -0
- package/dist/src/metrics.d.ts +467 -0
- package/dist/src/metrics.d.ts.map +1 -0
- package/dist/src/metrics.js +896 -0
- package/dist/src/metrics.js.map +1 -0
- package/dist/src/score/compute-score.d.ts +4 -0
- package/dist/src/score/compute-score.d.ts.map +1 -0
- package/dist/src/score/compute-score.js +75 -0
- package/dist/src/score/compute-score.js.map +1 -0
- package/dist/src/score/index.d.ts +4 -0
- package/dist/src/score/index.d.ts.map +1 -0
- package/dist/src/score/index.js +4 -0
- package/dist/src/score/index.js.map +1 -0
- package/dist/src/score/message-deliveries.d.ts +45 -0
- package/dist/src/score/message-deliveries.d.ts.map +1 -0
- package/dist/src/score/message-deliveries.js +75 -0
- package/dist/src/score/message-deliveries.js.map +1 -0
- package/dist/src/score/peer-score-params.d.ts +125 -0
- package/dist/src/score/peer-score-params.d.ts.map +1 -0
- package/dist/src/score/peer-score-params.js +159 -0
- package/dist/src/score/peer-score-params.js.map +1 -0
- package/dist/src/score/peer-score-thresholds.d.ts +31 -0
- package/dist/src/score/peer-score-thresholds.d.ts.map +1 -0
- package/dist/src/score/peer-score-thresholds.js +32 -0
- package/dist/src/score/peer-score-thresholds.js.map +1 -0
- package/dist/src/score/peer-score.d.ts +119 -0
- package/dist/src/score/peer-score.d.ts.map +1 -0
- package/dist/src/score/peer-score.js +459 -0
- package/dist/src/score/peer-score.js.map +1 -0
- package/dist/src/score/peer-stats.d.ts +32 -0
- package/dist/src/score/peer-stats.d.ts.map +1 -0
- package/dist/src/score/peer-stats.js +2 -0
- package/dist/src/score/peer-stats.js.map +1 -0
- package/dist/src/score/scoreMetrics.d.ts +23 -0
- package/dist/src/score/scoreMetrics.d.ts.map +1 -0
- package/dist/src/score/scoreMetrics.js +155 -0
- package/dist/src/score/scoreMetrics.js.map +1 -0
- package/dist/src/stream.d.ts +30 -0
- package/dist/src/stream.d.ts.map +1 -0
- package/dist/src/stream.js +55 -0
- package/dist/src/stream.js.map +1 -0
- package/dist/src/tracer.d.ts +53 -0
- package/dist/src/tracer.d.ts.map +1 -0
- package/dist/src/tracer.js +155 -0
- package/dist/src/tracer.js.map +1 -0
- package/dist/src/types.d.ts +148 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +90 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/buildRawMessage.d.ts +20 -0
- package/dist/src/utils/buildRawMessage.d.ts.map +1 -0
- package/dist/src/utils/buildRawMessage.js +151 -0
- package/dist/src/utils/buildRawMessage.js.map +1 -0
- package/dist/src/utils/create-gossip-rpc.d.ts +7 -0
- package/dist/src/utils/create-gossip-rpc.d.ts.map +1 -0
- package/dist/src/utils/create-gossip-rpc.js +31 -0
- package/dist/src/utils/create-gossip-rpc.js.map +1 -0
- package/dist/src/utils/index.d.ts +4 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +4 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/messageIdToString.d.ts +5 -0
- package/dist/src/utils/messageIdToString.d.ts.map +1 -0
- package/dist/src/utils/messageIdToString.js +8 -0
- package/dist/src/utils/messageIdToString.js.map +1 -0
- package/dist/src/utils/msgIdFn.d.ts +10 -0
- package/dist/src/utils/msgIdFn.d.ts.map +1 -0
- package/dist/src/utils/msgIdFn.js +23 -0
- package/dist/src/utils/msgIdFn.js.map +1 -0
- package/dist/src/utils/multiaddr.d.ts +3 -0
- package/dist/src/utils/multiaddr.d.ts.map +1 -0
- package/dist/src/utils/multiaddr.js +15 -0
- package/dist/src/utils/multiaddr.js.map +1 -0
- package/dist/src/utils/publishConfig.d.ts +8 -0
- package/dist/src/utils/publishConfig.d.ts.map +1 -0
- package/dist/src/utils/publishConfig.js +25 -0
- package/dist/src/utils/publishConfig.js.map +1 -0
- package/dist/src/utils/set.d.ts +14 -0
- package/dist/src/utils/set.d.ts.map +1 -0
- package/dist/src/utils/set.js +41 -0
- package/dist/src/utils/set.js.map +1 -0
- package/dist/src/utils/shuffle.d.ts +7 -0
- package/dist/src/utils/shuffle.d.ts.map +1 -0
- package/dist/src/utils/shuffle.js +21 -0
- package/dist/src/utils/shuffle.js.map +1 -0
- package/dist/src/utils/time-cache.d.ts +22 -0
- package/dist/src/utils/time-cache.d.ts.map +1 -0
- package/dist/src/utils/time-cache.js +54 -0
- package/dist/src/utils/time-cache.js.map +1 -0
- package/package.json +142 -0
- package/src/config.ts +31 -0
- package/src/constants.ts +261 -0
- package/src/errors.ts +17 -0
- package/src/gossipsub.ts +3061 -0
- package/src/index.ts +404 -0
- package/src/message/decodeRpc.ts +19 -0
- package/src/message/index.ts +1 -0
- package/src/message/rpc.proto +58 -0
- package/src/message/rpc.ts +848 -0
- package/src/message-cache.ts +196 -0
- package/src/metrics.ts +1014 -0
- package/src/score/compute-score.ts +98 -0
- package/src/score/index.ts +3 -0
- package/src/score/message-deliveries.ts +95 -0
- package/src/score/peer-score-params.ts +316 -0
- package/src/score/peer-score-thresholds.ts +70 -0
- package/src/score/peer-score.ts +565 -0
- package/src/score/peer-stats.ts +33 -0
- package/src/score/scoreMetrics.ts +215 -0
- package/src/stream.ts +79 -0
- package/src/tracer.ts +177 -0
- package/src/types.ts +178 -0
- package/src/utils/buildRawMessage.ts +174 -0
- package/src/utils/create-gossip-rpc.ts +34 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/messageIdToString.ts +8 -0
- package/src/utils/msgIdFn.ts +24 -0
- package/src/utils/multiaddr.ts +19 -0
- package/src/utils/publishConfig.ts +33 -0
- package/src/utils/set.ts +43 -0
- package/src/utils/shuffle.ts +21 -0
- package/src/utils/time-cache.ts +71 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { TypedEventEmitter, serviceCapabilities, serviceDependencies } from '@libp2p/interface';
|
|
2
|
+
import { StrictNoSign, StrictSign, TopicValidatorResult } from './index.ts';
|
|
3
|
+
import { RPC } from './message/rpc.js';
|
|
4
|
+
import { PeerScore } from './score/index.js';
|
|
5
|
+
import { InboundStream, OutboundStream } from './stream.js';
|
|
6
|
+
import { IWantTracer } from './tracer.js';
|
|
7
|
+
import type { GossipSubComponents, GossipSubEvents, GossipsubOpts, PublishResult, TopicValidatorFn } from './index.ts';
|
|
8
|
+
import type { PeerScoreParams, PeerScoreThresholds, PeerScoreStatsDump } from './score/index.js';
|
|
9
|
+
import type { TopicStr, MsgIdStr, PeerIdStr, PublishOpts } from './types.js';
|
|
10
|
+
import type { PeerId, Logger, TypedEventTarget } from '@libp2p/interface';
|
|
11
|
+
interface GossipOptions extends GossipsubOpts {
|
|
12
|
+
scoreParams: PeerScoreParams;
|
|
13
|
+
scoreThresholds: PeerScoreThresholds;
|
|
14
|
+
}
|
|
15
|
+
export declare class GossipSub extends TypedEventEmitter<GossipSubEvents> implements TypedEventTarget<GossipSubEvents> {
|
|
16
|
+
/**
|
|
17
|
+
* The signature policy to follow by default
|
|
18
|
+
*/
|
|
19
|
+
readonly globalSignaturePolicy: typeof StrictSign | typeof StrictNoSign;
|
|
20
|
+
protocols: string[];
|
|
21
|
+
private publishConfig;
|
|
22
|
+
private readonly dataTransform;
|
|
23
|
+
readonly peers: Map<string, PeerId>;
|
|
24
|
+
readonly streamsInbound: Map<string, InboundStream>;
|
|
25
|
+
readonly streamsOutbound: Map<string, OutboundStream>;
|
|
26
|
+
/** Ensures outbound streams are created sequentially */
|
|
27
|
+
private outboundInflightQueue;
|
|
28
|
+
/** Direct peers */
|
|
29
|
+
readonly direct: Set<string>;
|
|
30
|
+
/** Floodsub peers */
|
|
31
|
+
private readonly floodsubPeers;
|
|
32
|
+
/** Cache of seen messages */
|
|
33
|
+
private readonly seenCache;
|
|
34
|
+
/**
|
|
35
|
+
* Map of peer id and AcceptRequestWhileListEntry
|
|
36
|
+
*/
|
|
37
|
+
private readonly acceptFromWhitelist;
|
|
38
|
+
/**
|
|
39
|
+
* Map of topics to which peers are subscribed to
|
|
40
|
+
*/
|
|
41
|
+
private readonly topics;
|
|
42
|
+
/**
|
|
43
|
+
* List of our subscriptions
|
|
44
|
+
*/
|
|
45
|
+
private readonly subscriptions;
|
|
46
|
+
/**
|
|
47
|
+
* Map of topic meshes
|
|
48
|
+
* topic => peer id set
|
|
49
|
+
*/
|
|
50
|
+
readonly mesh: Map<string, Set<string>>;
|
|
51
|
+
/**
|
|
52
|
+
* Map of topics to set of peers. These mesh peers are the ones to which we are publishing without a topic membership
|
|
53
|
+
* topic => peer id set
|
|
54
|
+
*/
|
|
55
|
+
readonly fanout: Map<string, Set<string>>;
|
|
56
|
+
/**
|
|
57
|
+
* Map of last publish time for fanout topics
|
|
58
|
+
* topic => last publish time
|
|
59
|
+
*/
|
|
60
|
+
private readonly fanoutLastpub;
|
|
61
|
+
/**
|
|
62
|
+
* Map of pending messages to gossip
|
|
63
|
+
* peer id => control messages
|
|
64
|
+
*/
|
|
65
|
+
readonly gossip: Map<string, RPC.ControlIHave[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Map of control messages
|
|
68
|
+
* peer id => control message
|
|
69
|
+
*/
|
|
70
|
+
readonly control: Map<string, RPC.ControlMessage>;
|
|
71
|
+
/**
|
|
72
|
+
* Number of IHAVEs received from peer in the last heartbeat
|
|
73
|
+
*/
|
|
74
|
+
private readonly peerhave;
|
|
75
|
+
/** Number of messages we have asked from peer in the last heartbeat */
|
|
76
|
+
private readonly iasked;
|
|
77
|
+
/** Prune backoff map */
|
|
78
|
+
private readonly backoff;
|
|
79
|
+
/**
|
|
80
|
+
* Connection direction cache, marks peers with outbound connections
|
|
81
|
+
* peer id => direction
|
|
82
|
+
*/
|
|
83
|
+
private readonly outbound;
|
|
84
|
+
private readonly msgIdFn;
|
|
85
|
+
/**
|
|
86
|
+
* A fast message id function used for internal message de-duplication
|
|
87
|
+
*/
|
|
88
|
+
private readonly fastMsgIdFn;
|
|
89
|
+
private readonly msgIdToStrFn;
|
|
90
|
+
/** Maps fast message-id to canonical message-id */
|
|
91
|
+
private readonly fastMsgIdCache;
|
|
92
|
+
/**
|
|
93
|
+
* Short term cache for published message ids. This is used for penalizing peers sending
|
|
94
|
+
* our own messages back if the messages are anonymous or use a random author.
|
|
95
|
+
*/
|
|
96
|
+
private readonly publishedMessageIds;
|
|
97
|
+
/**
|
|
98
|
+
* A message cache that contains the messages for last few heartbeat ticks
|
|
99
|
+
*/
|
|
100
|
+
private readonly mcache;
|
|
101
|
+
/** Peer score tracking */
|
|
102
|
+
readonly score: PeerScore;
|
|
103
|
+
/**
|
|
104
|
+
* Custom validator function per topic.
|
|
105
|
+
* Must return or resolve quickly (< 100ms) to prevent causing penalties for late messages.
|
|
106
|
+
* If you need to apply validation that may require longer times use `asyncValidation` option and callback the
|
|
107
|
+
* validation result through `Gossipsub.reportValidationResult`
|
|
108
|
+
*/
|
|
109
|
+
readonly topicValidators: Map<string, TopicValidatorFn>;
|
|
110
|
+
/**
|
|
111
|
+
* Make this protected so child class may want to redirect to its own log.
|
|
112
|
+
*/
|
|
113
|
+
protected readonly log: Logger;
|
|
114
|
+
/**
|
|
115
|
+
* Number of heartbeats since the beginning of time
|
|
116
|
+
* This allows us to amortize some resource cleanup -- eg: backoff cleanup
|
|
117
|
+
*/
|
|
118
|
+
private heartbeatTicks;
|
|
119
|
+
/**
|
|
120
|
+
* Tracks IHAVE/IWANT promises broken by peers
|
|
121
|
+
*/
|
|
122
|
+
readonly gossipTracer: IWantTracer;
|
|
123
|
+
/**
|
|
124
|
+
* Tracks IDONTWANT messages received by peers in the current heartbeat
|
|
125
|
+
*/
|
|
126
|
+
private readonly idontwantCounts;
|
|
127
|
+
/**
|
|
128
|
+
* Tracks IDONTWANT messages received by peers and the heartbeat they were received in
|
|
129
|
+
*
|
|
130
|
+
* idontwants are stored for `mcacheLength` heartbeats before being pruned,
|
|
131
|
+
* so this map is bounded by peerCount * idontwantMaxMessages * mcacheLength
|
|
132
|
+
*/
|
|
133
|
+
private readonly idontwants;
|
|
134
|
+
private readonly components;
|
|
135
|
+
private directPeerInitial;
|
|
136
|
+
static multicodec: string;
|
|
137
|
+
readonly opts: Required<GossipOptions>;
|
|
138
|
+
private readonly decodeRpcLimits;
|
|
139
|
+
private readonly metrics;
|
|
140
|
+
private status;
|
|
141
|
+
private readonly maxInboundStreams?;
|
|
142
|
+
private readonly maxOutboundStreams?;
|
|
143
|
+
private readonly runOnLimitedConnection?;
|
|
144
|
+
private readonly allowedTopics;
|
|
145
|
+
private heartbeatTimer;
|
|
146
|
+
constructor(components: GossipSubComponents, options?: Partial<GossipsubOpts>);
|
|
147
|
+
readonly [Symbol.toStringTag] = "@chainsafe/libp2p-gossipsub";
|
|
148
|
+
readonly [serviceCapabilities]: string[];
|
|
149
|
+
readonly [serviceDependencies]: string[];
|
|
150
|
+
getPeers(): PeerId[];
|
|
151
|
+
isStarted(): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Mounts the gossipsub protocol onto the libp2p node and sends our
|
|
154
|
+
* our subscriptions to every peer connected
|
|
155
|
+
*/
|
|
156
|
+
start(): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Unmounts the gossipsub protocol and shuts down every connection
|
|
159
|
+
*/
|
|
160
|
+
stop(): Promise<void>;
|
|
161
|
+
/** FOR DEBUG ONLY - Dump peer stats for all peers. Data is cloned, safe to mutate */
|
|
162
|
+
dumpPeerScoreStats(): PeerScoreStatsDump;
|
|
163
|
+
/**
|
|
164
|
+
* On an inbound stream opened
|
|
165
|
+
*/
|
|
166
|
+
private onIncomingStream;
|
|
167
|
+
/**
|
|
168
|
+
* Registrar notifies an established connection with pubsub protocol
|
|
169
|
+
*/
|
|
170
|
+
private onPeerConnected;
|
|
171
|
+
/**
|
|
172
|
+
* Registrar notifies a closing connection with pubsub protocol
|
|
173
|
+
*/
|
|
174
|
+
private onPeerDisconnected;
|
|
175
|
+
private createOutboundStream;
|
|
176
|
+
private createInboundStream;
|
|
177
|
+
/**
|
|
178
|
+
* Add a peer to the router
|
|
179
|
+
*/
|
|
180
|
+
private addPeer;
|
|
181
|
+
/**
|
|
182
|
+
* Removes a peer from the router
|
|
183
|
+
*/
|
|
184
|
+
private removePeer;
|
|
185
|
+
get started(): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Get a the peer-ids in a topic mesh
|
|
188
|
+
*/
|
|
189
|
+
getMeshPeers(topic: TopicStr): PeerIdStr[];
|
|
190
|
+
/**
|
|
191
|
+
* Get a list of the peer-ids that are subscribed to one topic.
|
|
192
|
+
*/
|
|
193
|
+
getSubscribers(topic: TopicStr): PeerId[];
|
|
194
|
+
/**
|
|
195
|
+
* Get the list of topics which the peer is subscribed to.
|
|
196
|
+
*/
|
|
197
|
+
getTopics(): TopicStr[];
|
|
198
|
+
/**
|
|
199
|
+
* Responsible for processing each RPC message received by other peers.
|
|
200
|
+
*/
|
|
201
|
+
private pipePeerReadStream;
|
|
202
|
+
/**
|
|
203
|
+
* Handle error when read stream pipe throws, less of the functional use but more
|
|
204
|
+
* to for testing purposes to spy on the error handling
|
|
205
|
+
*/
|
|
206
|
+
private handlePeerReadStreamError;
|
|
207
|
+
/**
|
|
208
|
+
* Handles an rpc request from a peer
|
|
209
|
+
*/
|
|
210
|
+
handleReceivedRpc(from: PeerId, rpc: RPC): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* Handles a subscription change from a peer
|
|
213
|
+
*/
|
|
214
|
+
private handleReceivedSubscription;
|
|
215
|
+
/**
|
|
216
|
+
* Handles a newly received message from an RPC.
|
|
217
|
+
* May forward to all peers in the mesh.
|
|
218
|
+
*/
|
|
219
|
+
private handleReceivedMessage;
|
|
220
|
+
/**
|
|
221
|
+
* Handles a newly received message from an RPC.
|
|
222
|
+
* May forward to all peers in the mesh.
|
|
223
|
+
*/
|
|
224
|
+
private validateReceivedMessage;
|
|
225
|
+
/**
|
|
226
|
+
* Return score of a peer.
|
|
227
|
+
*/
|
|
228
|
+
getScore(peerId: PeerIdStr): number;
|
|
229
|
+
/**
|
|
230
|
+
* Send an rpc object to a peer with subscriptions
|
|
231
|
+
*/
|
|
232
|
+
private sendSubscriptions;
|
|
233
|
+
/**
|
|
234
|
+
* Handles an rpc control message from a peer
|
|
235
|
+
*/
|
|
236
|
+
private handleControlMessage;
|
|
237
|
+
/**
|
|
238
|
+
* Whether to accept a message from a peer
|
|
239
|
+
*/
|
|
240
|
+
acceptFrom(id: PeerIdStr): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Handles IHAVE messages
|
|
243
|
+
*/
|
|
244
|
+
private handleIHave;
|
|
245
|
+
/**
|
|
246
|
+
* Handles IWANT messages
|
|
247
|
+
* Returns messages to send back to peer
|
|
248
|
+
*/
|
|
249
|
+
private handleIWant;
|
|
250
|
+
/**
|
|
251
|
+
* Handles Graft messages
|
|
252
|
+
*/
|
|
253
|
+
private handleGraft;
|
|
254
|
+
/**
|
|
255
|
+
* Handles Prune messages
|
|
256
|
+
*/
|
|
257
|
+
private handlePrune;
|
|
258
|
+
private handleIdontwant;
|
|
259
|
+
/**
|
|
260
|
+
* Add standard backoff log for a peer in a topic
|
|
261
|
+
*/
|
|
262
|
+
private addBackoff;
|
|
263
|
+
/**
|
|
264
|
+
* Add backoff expiry interval for a peer in a topic
|
|
265
|
+
*
|
|
266
|
+
* @param id
|
|
267
|
+
* @param topic
|
|
268
|
+
* @param intervalMs - backoff duration in milliseconds
|
|
269
|
+
*/
|
|
270
|
+
private doAddBackoff;
|
|
271
|
+
/**
|
|
272
|
+
* Apply penalties from broken IHAVE/IWANT promises
|
|
273
|
+
*/
|
|
274
|
+
private applyIwantPenalties;
|
|
275
|
+
/**
|
|
276
|
+
* Clear expired backoff expiries
|
|
277
|
+
*/
|
|
278
|
+
private clearBackoff;
|
|
279
|
+
/**
|
|
280
|
+
* Maybe reconnect to direct peers
|
|
281
|
+
*/
|
|
282
|
+
private directConnect;
|
|
283
|
+
/**
|
|
284
|
+
* Maybe attempt connection given signed peer records
|
|
285
|
+
*/
|
|
286
|
+
private pxConnect;
|
|
287
|
+
/**
|
|
288
|
+
* Connect to a peer using the gossipsub protocol
|
|
289
|
+
*/
|
|
290
|
+
private connect;
|
|
291
|
+
/**
|
|
292
|
+
* Subscribes to a topic
|
|
293
|
+
*/
|
|
294
|
+
subscribe(topic: TopicStr): void;
|
|
295
|
+
/**
|
|
296
|
+
* Unsubscribe to a topic
|
|
297
|
+
*/
|
|
298
|
+
unsubscribe(topic: TopicStr): void;
|
|
299
|
+
/**
|
|
300
|
+
* Join topic
|
|
301
|
+
*/
|
|
302
|
+
private join;
|
|
303
|
+
/**
|
|
304
|
+
* Leave topic
|
|
305
|
+
*/
|
|
306
|
+
private leave;
|
|
307
|
+
private selectPeersToForward;
|
|
308
|
+
private selectPeersToPublish;
|
|
309
|
+
/**
|
|
310
|
+
* Forwards a message from our peers.
|
|
311
|
+
*
|
|
312
|
+
* For messages published by us (the app layer), this class uses `publish`
|
|
313
|
+
*/
|
|
314
|
+
private forwardMessage;
|
|
315
|
+
/**
|
|
316
|
+
* App layer publishes a message to peers, return number of peers this message is published to
|
|
317
|
+
* Note: `async` due to crypto only if `StrictSign`, otherwise it's a sync fn.
|
|
318
|
+
*
|
|
319
|
+
* For messages not from us, this class uses `forwardMessage`.
|
|
320
|
+
*/
|
|
321
|
+
publish(topic: TopicStr, data: Uint8Array, opts?: PublishOpts): Promise<PublishResult>;
|
|
322
|
+
/**
|
|
323
|
+
* Send the same data in batch to tosend list without considering cached control messages
|
|
324
|
+
* This is not only faster but also avoid allocating memory for each peer
|
|
325
|
+
* see https://github.com/ChainSafe/js-libp2p-gossipsub/issues/344
|
|
326
|
+
*/
|
|
327
|
+
private sendRpcInBatch;
|
|
328
|
+
/**
|
|
329
|
+
* This function should be called when `asyncValidation` is `true` after
|
|
330
|
+
* the message got validated by the caller. Messages are stored in the `mcache` and
|
|
331
|
+
* validation is expected to be fast enough that the messages should still exist in the cache.
|
|
332
|
+
* There are three possible validation outcomes and the outcome is given in acceptance.
|
|
333
|
+
*
|
|
334
|
+
* If acceptance = `MessageAcceptance.Accept` the message will get propagated to the
|
|
335
|
+
* network. The `propagation_source` parameter indicates who the message was received by and
|
|
336
|
+
* will not be forwarded back to that peer.
|
|
337
|
+
*
|
|
338
|
+
* If acceptance = `MessageAcceptance.Reject` the message will be deleted from the memcache
|
|
339
|
+
* and the P₄ penalty will be applied to the `propagationSource`.
|
|
340
|
+
*
|
|
341
|
+
* If acceptance = `MessageAcceptance.Ignore` the message will be deleted from the memcache
|
|
342
|
+
* but no P₄ penalty will be applied.
|
|
343
|
+
*
|
|
344
|
+
* This function will return true if the message was found in the cache and false if was not
|
|
345
|
+
* in the cache anymore.
|
|
346
|
+
*
|
|
347
|
+
* This should only be called once per message.
|
|
348
|
+
*/
|
|
349
|
+
reportMessageValidationResult(msgId: MsgIdStr, propagationSource: PeerIdStr, acceptance: TopicValidatorResult): void;
|
|
350
|
+
/**
|
|
351
|
+
* Sends a GRAFT message to a peer
|
|
352
|
+
*/
|
|
353
|
+
private sendGraft;
|
|
354
|
+
/**
|
|
355
|
+
* Sends a PRUNE message to a peer
|
|
356
|
+
*/
|
|
357
|
+
private sendPrune;
|
|
358
|
+
private sendIDontWants;
|
|
359
|
+
/**
|
|
360
|
+
* Send an rpc object to a peer
|
|
361
|
+
*/
|
|
362
|
+
private sendRpc;
|
|
363
|
+
/** Mutates `outRpc` adding graft and prune control messages */
|
|
364
|
+
piggybackControl(id: PeerIdStr, outRpc: RPC, ctrl: RPC.ControlMessage): void;
|
|
365
|
+
/** Mutates `outRpc` adding ihave control messages */
|
|
366
|
+
private piggybackGossip;
|
|
367
|
+
/**
|
|
368
|
+
* Send graft and prune messages
|
|
369
|
+
*
|
|
370
|
+
* @param tograft - peer id => topic[]
|
|
371
|
+
* @param toprune - peer id => topic[]
|
|
372
|
+
*/
|
|
373
|
+
private sendGraftPrune;
|
|
374
|
+
/**
|
|
375
|
+
* Emits gossip - Send IHAVE messages to a random set of gossip peers
|
|
376
|
+
*/
|
|
377
|
+
private emitGossip;
|
|
378
|
+
/**
|
|
379
|
+
* Send gossip messages to GossipFactor peers above threshold with a minimum of D_lazy
|
|
380
|
+
* Peers are randomly selected from the heartbeat which exclude mesh + fanout peers
|
|
381
|
+
* We also exclude direct peers, as there is no reason to emit gossip to them
|
|
382
|
+
*
|
|
383
|
+
* @param topic
|
|
384
|
+
* @param candidateToGossip - peers to gossip
|
|
385
|
+
* @param messageIDs - message ids to gossip
|
|
386
|
+
*/
|
|
387
|
+
private doEmitGossip;
|
|
388
|
+
/**
|
|
389
|
+
* Flush gossip and control messages
|
|
390
|
+
*/
|
|
391
|
+
private flush;
|
|
392
|
+
/**
|
|
393
|
+
* Adds new IHAVE messages to pending gossip
|
|
394
|
+
*/
|
|
395
|
+
private pushGossip;
|
|
396
|
+
/**
|
|
397
|
+
* Make a PRUNE control message for a peer in a topic
|
|
398
|
+
*/
|
|
399
|
+
private makePrune;
|
|
400
|
+
private readonly runHeartbeat;
|
|
401
|
+
/**
|
|
402
|
+
* Maintains the mesh and fanout maps in gossipsub.
|
|
403
|
+
*/
|
|
404
|
+
heartbeat(): Promise<void>;
|
|
405
|
+
/**
|
|
406
|
+
* Given a topic, returns up to count peers subscribed to that topic
|
|
407
|
+
* that pass an optional filter function
|
|
408
|
+
*
|
|
409
|
+
* @param topic
|
|
410
|
+
* @param count
|
|
411
|
+
* @param filter - a function to filter acceptable peers
|
|
412
|
+
*/
|
|
413
|
+
private getRandomGossipPeers;
|
|
414
|
+
private onScrapeMetrics;
|
|
415
|
+
private readonly tagMeshPeer;
|
|
416
|
+
private readonly untagMeshPeer;
|
|
417
|
+
}
|
|
418
|
+
export {};
|
|
419
|
+
//# sourceMappingURL=gossipsub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gossipsub.d.ts","sourceRoot":"","sources":["../../src/gossipsub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAa/F,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAE3E,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAWtC,OAAO,EACL,SAAS,EAKV,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC3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