Skip to content

Commit

Permalink
chore!: change all instances of PubSubTopic to PubsubTopic (#1703)
Browse files Browse the repository at this point in the history
* rename all PubSub patterns

* feat: forbid identifiers with camelcase pubSub (#1709)

---------

Co-authored-by: Arseniy Klempner <[email protected]>
  • Loading branch information
danisharora099 and adklempner authored Nov 14, 2023
1 parent 535a748 commit 3166a51
Show file tree
Hide file tree
Showing 48 changed files with 288 additions and 287 deletions.
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"Привет",
"مرحبا"
],
"flagWords": ["pubSub", "pubSubTopics", "pubSubTopic"],
"flagWords": ["pubSub: pubsub", "pubSubTopics: pubsubTopics", "pubSubTopic: pubsubTopic", "PubSub: Pubsub", "PubSubTopics: PubsubTopics", "PubSubTopic: PubsubTopic", "DefaultPubSubTopic: DefaultPubsubTopic"],
"ignorePaths": [
"package.json",
"package-lock.json",
Expand Down
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-explicit-any": "warn"
"@typescript-eslint/no-explicit-any": "warn",
"id-match": ["error", "^(?!.*[pP]ubSub)"]
},
"overrides": [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { DefaultUserAgent } from "./lib/waku.js";
export { DefaultPubSubTopic } from "./lib/constants.js";
export { DefaultPubsubTopic } from "./lib/constants.js";
export { createEncoder, createDecoder } from "./lib/message/version_0.js";
export type {
Encoder,
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/lib/connection_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
IRelay,
KeepAliveOptions,
PeersByDiscoveryResult,
PubSubTopic,
PubsubTopic,
ShardInfo
} from "@waku/interfaces";
import { Libp2p, Tags } from "@waku/interfaces";
import { shardInfoToPubSubTopics } from "@waku/utils";
import { shardInfoToPubsubTopics } from "@waku/utils";
import { Logger } from "@waku/utils";

import { KeepAliveManager } from "./keep_alive_manager.js";
Expand Down Expand Up @@ -45,7 +45,7 @@ export class ConnectionManager
peerId: string,
libp2p: Libp2p,
keepAliveOptions: KeepAliveOptions,
pubsubTopics: PubSubTopic[],
pubsubTopics: PubsubTopic[],
relay?: IRelay,
options?: ConnectionManagerOptions
): ConnectionManager {
Expand Down Expand Up @@ -111,13 +111,13 @@ export class ConnectionManager
private constructor(
libp2p: Libp2p,
keepAliveOptions: KeepAliveOptions,
private configuredPubSubTopics: PubSubTopic[],
private configuredPubsubTopics: PubsubTopic[],
relay?: IRelay,
options?: Partial<ConnectionManagerOptions>
) {
super();
this.libp2p = libp2p;
this.configuredPubSubTopics = configuredPubSubTopics;
this.configuredPubsubTopics = configuredPubsubTopics;
this.options = {
maxDialAttemptsForPeer: DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER,
maxBootstrapPeersAllowed: DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED,
Expand Down Expand Up @@ -426,7 +426,7 @@ export class ConnectionManager
);
log.warn(
`Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${
this.configuredPubSubTopics
this.configuredPubsubTopics
}).
Not dialing.`
);
Expand Down Expand Up @@ -518,10 +518,10 @@ export class ConnectionManager
// If there's no shard information, simply return true
if (!shardInfo) return true;

const pubsubTopics = shardInfoToPubSubTopics(shardInfo);
const pubsubTopics = shardInfoToPubsubTopics(shardInfo);

const isTopicConfigured = pubsubTopics.some((topic) =>
this.configuredPubSubTopics.includes(topic)
this.configuredPubsubTopics.includes(topic)
);
return isTopicConfigured;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* DefaultPubSubTopic is the default gossipsub topic to use for Waku.
* DefaultPubsubTopic is the default gossipsub topic to use for Waku.
*/
export const DefaultPubSubTopic = "/waku/2/default-waku/proto";
export const DefaultPubsubTopic = "/waku/2/default-waku/proto";
22 changes: 11 additions & 11 deletions packages/core/src/lib/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
Libp2p,
PeerIdStr,
ProtocolCreateOptions,
PubSubTopic,
PubsubTopic,
Unsubscribe
} from "@waku/interfaces";
import { WakuMessage } from "@waku/proto";
Expand All @@ -28,7 +28,7 @@ import * as lp from "it-length-prefixed";
import { pipe } from "it-pipe";

import { BaseProtocol } from "../base_protocol.js";
import { DefaultPubSubTopic } from "../constants.js";
import { DefaultPubsubTopic } from "../constants.js";

import {
FilterPushRpc,
Expand All @@ -50,7 +50,7 @@ export const FilterCodecs = {

class Subscription {
private readonly peer: Peer;
private readonly pubsubTopic: PubSubTopic;
private readonly pubsubTopic: PubsubTopic;
private newStream: (peer: Peer) => Promise<Stream>;

private subscriptionCallbacks: Map<
Expand All @@ -59,7 +59,7 @@ class Subscription {
>;

constructor(
pubsubTopic: PubSubTopic,
pubsubTopic: PubsubTopic,
remotePeer: Peer,
newStream: (peer: Peer) => Promise<Stream>
) {
Expand Down Expand Up @@ -256,19 +256,19 @@ class Subscription {
}

class Filter extends BaseProtocol implements IReceiver {
private readonly pubsubTopics: PubSubTopic[] = [];
private readonly pubsubTopics: PubsubTopic[] = [];
private activeSubscriptions = new Map<string, Subscription>();
private readonly NUM_PEERS_PROTOCOL = 1;

private getActiveSubscription(
pubsubTopic: PubSubTopic,
pubsubTopic: PubsubTopic,
peerIdStr: PeerIdStr
): Subscription | undefined {
return this.activeSubscriptions.get(`${pubsubTopic}_${peerIdStr}`);
}

private setActiveSubscription(
pubsubTopic: PubSubTopic,
pubsubTopic: PubsubTopic,
peerIdStr: PeerIdStr,
subscription: Subscription
): Subscription {
Expand All @@ -279,7 +279,7 @@ class Filter extends BaseProtocol implements IReceiver {
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
super(FilterCodecs.SUBSCRIBE, libp2p.components);

this.pubsubTopics = options?.pubsubTopics || [DefaultPubSubTopic];
this.pubsubTopics = options?.pubsubTopics || [DefaultPubsubTopic];

libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
log.error("Failed to register ", FilterCodecs.PUSH, e);
Expand All @@ -289,7 +289,7 @@ class Filter extends BaseProtocol implements IReceiver {
}

async createSubscription(
pubsubTopic: string = DefaultPubSubTopic
pubsubTopic: string = DefaultPubsubTopic
): Promise<Subscription> {
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);

Expand Down Expand Up @@ -367,7 +367,7 @@ class Filter extends BaseProtocol implements IReceiver {
}

if (!pubsubTopic) {
log.error("PubSub topic missing from push message");
log.error("Pubsub topic missing from push message");
return;
}

Expand Down Expand Up @@ -408,7 +408,7 @@ export function wakuFilter(

async function pushMessage<T extends IDecodedMessage>(
subscriptionCallback: SubscriptionCallback<T>,
pubsubTopic: PubSubTopic,
pubsubTopic: PubsubTopic,
message: WakuMessage
): Promise<void> {
const { decoders, callback } = subscriptionCallback;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/keep_alive_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class KeepAliveManager {
relayPeriodSecs: number,
peerIdStr: PeerIdStr
): NodeJS.Timeout[] {
// send a ping message to each PubSubTopic the peer is part of
// send a ping message to each PubsubTopic the peer is part of
const intervals: NodeJS.Timeout[] = [];
for (const topic of relay.pubsubTopics) {
const meshPeers = relay.getMeshPeers(topic);
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/lib/light_push/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IMessage,
Libp2p,
ProtocolCreateOptions,
PubSubTopic,
PubsubTopic,
SendError,
SendResult
} from "@waku/interfaces";
Expand All @@ -22,7 +22,7 @@ import { pipe } from "it-pipe";
import { Uint8ArrayList } from "uint8arraylist";

import { BaseProtocol } from "../base_protocol.js";
import { DefaultPubSubTopic } from "../constants.js";
import { DefaultPubsubTopic } from "../constants.js";

import { PushRpc } from "./push_rpc.js";

Expand All @@ -45,12 +45,12 @@ type PreparePushMessageResult =
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
*/
class LightPush extends BaseProtocol implements ILightPush {
private readonly pubsubTopics: PubSubTopic[];
private readonly pubsubTopics: PubsubTopic[];
private readonly NUM_PEERS_PROTOCOL = 1;

constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
super(LightPushCodec, libp2p.components);
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic];
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubsubTopic];
}

private async preparePushMessage(
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/lib/message/version_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import type {
IMetaSetter,
IProtoMessage,
IRateLimitProof,
PubSubTopic
PubsubTopic
} from "@waku/interfaces";
import { proto_message as proto } from "@waku/proto";
import { Logger } from "@waku/utils";

import { DefaultPubSubTopic } from "../constants.js";
import { DefaultPubsubTopic } from "../constants.js";

const log = new Logger("message:version-0");
const OneMillion = BigInt(1_000_000);
Expand Down Expand Up @@ -76,7 +76,7 @@ export class Encoder implements IEncoder {
constructor(
public contentTopic: string,
public ephemeral: boolean = false,
public pubsubTopic: PubSubTopic,
public pubsubTopic: PubsubTopic,
public metaSetter?: IMetaSetter
) {
if (!contentTopic || contentTopic === "") {
Expand Down Expand Up @@ -119,7 +119,7 @@ export class Encoder implements IEncoder {
* messages.
*/
export function createEncoder({
pubsubTopic = DefaultPubSubTopic,
pubsubTopic = DefaultPubsubTopic,
contentTopic,
ephemeral,
metaSetter
Expand All @@ -129,7 +129,7 @@ export function createEncoder({

export class Decoder implements IDecoder<DecodedMessage> {
constructor(
public pubsubTopic: PubSubTopic,
public pubsubTopic: PubsubTopic,
public contentTopic: string
) {
if (!contentTopic || contentTopic === "") {
Expand Down Expand Up @@ -182,7 +182,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
*/
export function createDecoder(
contentTopic: string,
pubsubTopic: PubSubTopic = DefaultPubSubTopic
pubsubTopic: PubsubTopic = DefaultPubsubTopic
): Decoder {
return new Decoder(pubsubTopic, contentTopic);
}
26 changes: 13 additions & 13 deletions packages/core/src/lib/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IStore,
Libp2p,
ProtocolCreateOptions,
PubSubTopic
PubsubTopic
} from "@waku/interfaces";
import { proto_store as proto } from "@waku/proto";
import { ensurePubsubTopicIsConfigured, isDefined } from "@waku/utils";
Expand All @@ -19,7 +19,7 @@ import { pipe } from "it-pipe";
import { Uint8ArrayList } from "uint8arraylist";

import { BaseProtocol } from "../base_protocol.js";
import { DefaultPubSubTopic } from "../constants.js";
import { DefaultPubsubTopic } from "../constants.js";
import { toProtoMessage } from "../to_proto_message.js";

import { HistoryRpc, PageDirection, Params } from "./history_rpc.js";
Expand Down Expand Up @@ -75,12 +75,12 @@ export interface QueryOptions {
* The Waku Store protocol can be used to retrieved historical messages.
*/
class Store extends BaseProtocol implements IStore {
private readonly pubsubTopics: PubSubTopic[];
private readonly pubsubTopics: PubsubTopic[];
private readonly NUM_PEERS_PROTOCOL = 1;

constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
super(StoreCodec, libp2p.components);
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic];
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubsubTopic];
}

/**
Expand Down Expand Up @@ -230,29 +230,29 @@ class Store extends BaseProtocol implements IStore {
}

// convert array to set to remove duplicates
const uniquePubSubTopicsInQuery = Array.from(
const uniquePubsubTopicsInQuery = Array.from(
new Set(decoders.map((decoder) => decoder.pubsubTopic))
);

// If multiple pubsub topics are provided, throw an error
if (uniquePubSubTopicsInQuery.length > 1) {
if (uniquePubsubTopicsInQuery.length > 1) {
throw new Error(
"API does not support querying multiple pubsub topics at once"
);
}

// we can be certain that there is only one pubsub topic in the query
const pubSubTopicForQuery = uniquePubSubTopicsInQuery[0];
const pubsubTopicForQuery = uniquePubsubTopicsInQuery[0];

ensurePubsubTopicIsConfigured(pubSubTopicForQuery, this.pubsubTopics);
ensurePubsubTopicIsConfigured(pubsubTopicForQuery, this.pubsubTopics);

// check that the pubsubTopic from the Cursor and Decoder match
if (
options?.cursor?.pubsubTopic &&
options.cursor.pubsubTopic !== pubSubTopicForQuery
options.cursor.pubsubTopic !== pubsubTopicForQuery
) {
throw new Error(
`Cursor pubsub topic (${options?.cursor?.pubsubTopic}) does not match decoder pubsub topic (${pubSubTopicForQuery})`
`Cursor pubsub topic (${options?.cursor?.pubsubTopic}) does not match decoder pubsub topic (${pubsubTopicForQuery})`
);
}

Expand All @@ -267,16 +267,16 @@ class Store extends BaseProtocol implements IStore {
});

const contentTopics = decoders
.filter((decoder) => decoder.pubsubTopic === pubSubTopicForQuery)
.filter((decoder) => decoder.pubsubTopic === pubsubTopicForQuery)
.map((dec) => dec.contentTopic);

if (contentTopics.length === 0) {
throw new Error("No decoders found for topic " + pubSubTopicForQuery);
throw new Error("No decoders found for topic " + pubsubTopicForQuery);
}

const queryOpts = Object.assign(
{
pubsubTopic: pubSubTopicForQuery,
pubsubTopic: pubsubTopicForQuery,
pageDirection: PageDirection.BACKWARD,
pageSize: DefaultPageSize
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/waku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
IRelay,
IStore,
Libp2p,
PubSubTopic,
PubsubTopic,
Waku
} from "@waku/interfaces";
import { Protocols } from "@waku/interfaces";
Expand Down Expand Up @@ -53,7 +53,7 @@ export class WakuNode implements Waku {

constructor(
options: WakuOptions,
public readonly pubsubTopics: PubSubTopic[],
public readonly pubsubTopics: PubsubTopic[],
libp2p: Libp2p,
store?: (libp2p: Libp2p) => IStore,
lightPush?: (libp2p: Libp2p) => ILightPush,
Expand Down
Loading

0 comments on commit 3166a51

Please sign in to comment.