Skip to content

Commit

Permalink
fix: createDecoder interface
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Nov 22, 2023
1 parent 973ab4f commit ab4831c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/lib/keep_alive_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PeerId } from "@libp2p/interface/peer-id";
import type { PeerStore } from "@libp2p/interface/peer-store";
import type { IRelay, PeerIdStr } from "@waku/interfaces";
import type { KeepAliveOptions } from "@waku/interfaces";
import { Logger, pubsubTopicToShardInfo } from "@waku/utils";
import { Logger, pubsubTopicToSingleTopicShardInfo } from "@waku/utils";
import { utf8ToBytes } from "@waku/utils/bytes";
import type { PingService } from "libp2p/ping";

Expand Down Expand Up @@ -123,7 +123,7 @@ export class KeepAliveManager {
if (!meshPeers.includes(peerIdStr)) continue;

const encoder = createEncoder({
pubsubTopicShardInfo: pubsubTopicToShardInfo(topic),
pubsubTopicShardInfo: pubsubTopicToSingleTopicShardInfo(topic),
contentTopic: RelayPingContentTopic,
ephemeral: true
});
Expand Down
2 changes: 1 addition & 1 deletion packages/interfaces/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface IMetaSetter {
}

export interface EncoderOptions {
pubsubTopic?: SingleTopicShardInfo | PubsubTopic;
pubsubTopicShardInfo?: SingleTopicShardInfo;
/** The content topic to set on outgoing messages. */
contentTopic: string;
/**
Expand Down
26 changes: 10 additions & 16 deletions packages/utils/src/common/sharding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,16 @@ export const shardInfoToPubsubTopics = (
);
};

export const pubsubTopicToShardInfo = (
pubsubTopics: PubsubTopic[]
): ShardInfo => {
const indexList: number[] = [];
const cluster = parseInt(pubsubTopics[0].split("/")[4]);
for (const topic of pubsubTopics) {
const topicCluster = parseInt(topic.split("/")[4]);
if (topicCluster !== cluster) {
throw new Error(
"Pubsub topics must be from the same cluster to convert to shard info"
);
}
const index = parseInt(topic.split("/")[5]);
indexList.push(index);
}
return { cluster, indexList };
export const pubsubTopicToSingleTopicShardInfo = (
pubsubTopics: PubsubTopic
): SingleTopicShardInfo => {
const parts = pubsubTopics.split("/");
if (parts.length != 5) throw new Error("Invalid pubsub topic");

return {
cluster: parseInt(parts[3]),
index: parseInt(parts[4])
};
};

export function ensurePubsubTopicIsConfigured(
Expand Down

0 comments on commit ab4831c

Please sign in to comment.