Skip to content

Commit

Permalink
Add skipDuplicateCheck option
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Aug 13, 2022
1 parent 9f0be04 commit 8f7ec78
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type ReceivedMessageResult =
| ({ code: MessageStatus.invalid; msgIdStr?: MsgIdStr } & RejectReasonObj)
| { code: MessageStatus.valid; messageId: MessageId; msg: Message }

export type PublishOpts = {
skipDuplicateCheck: boolean
}

export const multicodec: string = constants.GossipsubIDv11

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

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

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

0 comments on commit 8f7ec78

Please sign in to comment.