Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow publishing same message on multiple topics #326

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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