Skip to content

Commit 8f7ec78

Browse files
committed
Add skipDuplicateCheck option
1 parent 9f0be04 commit 8f7ec78

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ type ReceivedMessageResult =
8585
| ({ code: MessageStatus.invalid; msgIdStr?: MsgIdStr } & RejectReasonObj)
8686
| { code: MessageStatus.valid; messageId: MessageId; msg: Message }
8787

88+
export type PublishOpts = {
89+
skipDuplicateCheck: boolean
90+
}
91+
8892
export const multicodec: string = constants.GossipsubIDv11
8993

9094
export interface GossipsubOpts extends GossipsubOptsSpec, PubSubInit {
@@ -1922,7 +1926,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements Initiali
19221926
*
19231927
* For messages not from us, this class uses `forwardMessage`.
19241928
*/
1925-
async publish(topic: TopicStr, data: Uint8Array): Promise<PublishResult> {
1929+
async publish(topic: TopicStr, data: Uint8Array, opts?: PublishOpts): Promise<PublishResult> {
19261930
const transformedData = this.dataTransform ? this.dataTransform.outboundTransform(topic, data) : data
19271931

19281932
if (this.publishConfig == null) {
@@ -1936,7 +1940,7 @@ export class GossipSub extends EventEmitter<GossipsubEvents> implements Initiali
19361940
const msgId = await this.msgIdFn(msg)
19371941
const msgIdStr = this.msgIdToStrFn(msgId)
19381942

1939-
if (this.seenCache.has(msgIdStr)) {
1943+
if (!opts?.skipDuplicateCheck && this.seenCache.has(msgIdStr)) {
19401944
// This message has already been seen. We don't re-publish messages that have already
19411945
// been published on the network.
19421946
throw Error('PublishError.Duplicate')

0 commit comments

Comments
 (0)