Skip to content

Commit 6f9f98b

Browse files
rename all PubSub patterns
1 parent 678635e commit 6f9f98b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+286
-286
lines changed

.cspell.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"Привет",
124124
"مرحبا"
125125
],
126-
"flagWords": ["pubSub", "pubSubTopics", "pubSubTopic"],
126+
"flagWords": ["pubSub: pubsub", "pubSubTopics: pubsubTopics", "pubSubTopic: pubsubTopic", "PubSub: Pubsub", "PubSubTopics: PubsubTopics", "PubSubTopic: PubsubTopic", "DefaultPubSubTopic: DefaultPubsubTopic"],
127127
"ignorePaths": [
128128
"package.json",
129129
"package-lock.json",

packages/core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { DefaultUserAgent } from "./lib/waku.js";
2-
export { DefaultPubSubTopic } from "./lib/constants.js";
2+
export { DefaultPubsubTopic } from "./lib/constants.js";
33
export { createEncoder, createDecoder } from "./lib/message/version_0.js";
44
export type {
55
Encoder,

packages/core/src/lib/connection_manager.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import {
1212
IRelay,
1313
KeepAliveOptions,
1414
PeersByDiscoveryResult,
15-
PubSubTopic,
15+
PubsubTopic,
1616
ShardInfo
1717
} from "@waku/interfaces";
1818
import { Libp2p, Tags } from "@waku/interfaces";
19-
import { shardInfoToPubSubTopics } from "@waku/utils";
19+
import { shardInfoToPubsubTopics } from "@waku/utils";
2020
import { Logger } from "@waku/utils";
2121

2222
import { KeepAliveManager } from "./keep_alive_manager.js";
@@ -45,7 +45,7 @@ export class ConnectionManager
4545
peerId: string,
4646
libp2p: Libp2p,
4747
keepAliveOptions: KeepAliveOptions,
48-
pubsubTopics: PubSubTopic[],
48+
pubsubTopics: PubsubTopic[],
4949
relay?: IRelay,
5050
options?: ConnectionManagerOptions
5151
): ConnectionManager {
@@ -111,13 +111,13 @@ export class ConnectionManager
111111
private constructor(
112112
libp2p: Libp2p,
113113
keepAliveOptions: KeepAliveOptions,
114-
private configuredPubSubTopics: PubSubTopic[],
114+
private configuredPubsubTopics: PubsubTopic[],
115115
relay?: IRelay,
116116
options?: Partial<ConnectionManagerOptions>
117117
) {
118118
super();
119119
this.libp2p = libp2p;
120-
this.configuredPubSubTopics = configuredPubSubTopics;
120+
this.configuredPubsubTopics = configuredPubsubTopics;
121121
this.options = {
122122
maxDialAttemptsForPeer: DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER,
123123
maxBootstrapPeersAllowed: DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED,
@@ -426,7 +426,7 @@ export class ConnectionManager
426426
);
427427
log.warn(
428428
`Discovered peer ${peerId.toString()} with ShardInfo ${shardInfo} is not part of any of the configured pubsub topics (${
429-
this.configuredPubSubTopics
429+
this.configuredPubsubTopics
430430
}).
431431
Not dialing.`
432432
);
@@ -518,10 +518,10 @@ export class ConnectionManager
518518
// If there's no shard information, simply return true
519519
if (!shardInfo) return true;
520520

521-
const pubsubTopics = shardInfoToPubSubTopics(shardInfo);
521+
const pubsubTopics = shardInfoToPubsubTopics(shardInfo);
522522

523523
const isTopicConfigured = pubsubTopics.some((topic) =>
524-
this.configuredPubSubTopics.includes(topic)
524+
this.configuredPubsubTopics.includes(topic)
525525
);
526526
return isTopicConfigured;
527527
}

packages/core/src/lib/constants.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
2-
* DefaultPubSubTopic is the default gossipsub topic to use for Waku.
2+
* DefaultPubsubTopic is the default gossipsub topic to use for Waku.
33
*/
4-
export const DefaultPubSubTopic = "/waku/2/default-waku/proto";
4+
export const DefaultPubsubTopic = "/waku/2/default-waku/proto";

packages/core/src/lib/filter/index.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
Libp2p,
1414
PeerIdStr,
1515
ProtocolCreateOptions,
16-
PubSubTopic,
16+
PubsubTopic,
1717
Unsubscribe
1818
} from "@waku/interfaces";
1919
import { WakuMessage } from "@waku/proto";
@@ -28,7 +28,7 @@ import * as lp from "it-length-prefixed";
2828
import { pipe } from "it-pipe";
2929

3030
import { BaseProtocol } from "../base_protocol.js";
31-
import { DefaultPubSubTopic } from "../constants.js";
31+
import { DefaultPubsubTopic } from "../constants.js";
3232

3333
import {
3434
FilterPushRpc,
@@ -50,7 +50,7 @@ export const FilterCodecs = {
5050

5151
class Subscription {
5252
private readonly peer: Peer;
53-
private readonly pubsubTopic: PubSubTopic;
53+
private readonly pubsubTopic: PubsubTopic;
5454
private newStream: (peer: Peer) => Promise<Stream>;
5555

5656
private subscriptionCallbacks: Map<
@@ -59,7 +59,7 @@ class Subscription {
5959
>;
6060

6161
constructor(
62-
pubsubTopic: PubSubTopic,
62+
pubsubTopic: PubsubTopic,
6363
remotePeer: Peer,
6464
newStream: (peer: Peer) => Promise<Stream>
6565
) {
@@ -256,19 +256,19 @@ class Subscription {
256256
}
257257

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

263263
private getActiveSubscription(
264-
pubsubTopic: PubSubTopic,
264+
pubsubTopic: PubsubTopic,
265265
peerIdStr: PeerIdStr
266266
): Subscription | undefined {
267267
return this.activeSubscriptions.get(`${pubsubTopic}_${peerIdStr}`);
268268
}
269269

270270
private setActiveSubscription(
271-
pubsubTopic: PubSubTopic,
271+
pubsubTopic: PubsubTopic,
272272
peerIdStr: PeerIdStr,
273273
subscription: Subscription
274274
): Subscription {
@@ -279,7 +279,7 @@ class Filter extends BaseProtocol implements IReceiver {
279279
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
280280
super(FilterCodecs.SUBSCRIBE, libp2p.components);
281281

282-
this.pubsubTopics = options?.pubsubTopics || [DefaultPubSubTopic];
282+
this.pubsubTopics = options?.pubsubTopics || [DefaultPubsubTopic];
283283

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

291291
async createSubscription(
292-
pubsubTopic: string = DefaultPubSubTopic
292+
pubsubTopic: string = DefaultPubsubTopic
293293
): Promise<Subscription> {
294294
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
295295

@@ -367,7 +367,7 @@ class Filter extends BaseProtocol implements IReceiver {
367367
}
368368

369369
if (!pubsubTopic) {
370-
log.error("PubSub topic missing from push message");
370+
log.error("Pubsub topic missing from push message");
371371
return;
372372
}
373373

@@ -408,7 +408,7 @@ export function wakuFilter(
408408

409409
async function pushMessage<T extends IDecodedMessage>(
410410
subscriptionCallback: SubscriptionCallback<T>,
411-
pubsubTopic: PubSubTopic,
411+
pubsubTopic: PubsubTopic,
412412
message: WakuMessage
413413
): Promise<void> {
414414
const { decoders, callback } = subscriptionCallback;

packages/core/src/lib/keep_alive_manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class KeepAliveManager {
116116
relayPeriodSecs: number,
117117
peerIdStr: PeerIdStr
118118
): NodeJS.Timeout[] {
119-
// send a ping message to each PubSubTopic the peer is part of
119+
// send a ping message to each PubsubTopic the peer is part of
120120
const intervals: NodeJS.Timeout[] = [];
121121
for (const topic of relay.pubsubTopics) {
122122
const meshPeers = relay.getMeshPeers(topic);

packages/core/src/lib/light_push/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
IMessage,
77
Libp2p,
88
ProtocolCreateOptions,
9-
PubSubTopic,
9+
PubsubTopic,
1010
SendError,
1111
SendResult
1212
} from "@waku/interfaces";
@@ -22,7 +22,7 @@ import { pipe } from "it-pipe";
2222
import { Uint8ArrayList } from "uint8arraylist";
2323

2424
import { BaseProtocol } from "../base_protocol.js";
25-
import { DefaultPubSubTopic } from "../constants.js";
25+
import { DefaultPubsubTopic } from "../constants.js";
2626

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

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

5151
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
5252
super(LightPushCodec, libp2p.components);
53-
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic];
53+
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubsubTopic];
5454
}
5555

5656
private async preparePushMessage(

packages/core/src/lib/message/version_0.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import type {
77
IMetaSetter,
88
IProtoMessage,
99
IRateLimitProof,
10-
PubSubTopic
10+
PubsubTopic
1111
} from "@waku/interfaces";
1212
import { proto_message as proto } from "@waku/proto";
1313
import { Logger } from "@waku/utils";
1414

15-
import { DefaultPubSubTopic } from "../constants.js";
15+
import { DefaultPubsubTopic } from "../constants.js";
1616

1717
const log = new Logger("message:version-0");
1818
const OneMillion = BigInt(1_000_000);
@@ -76,7 +76,7 @@ export class Encoder implements IEncoder {
7676
constructor(
7777
public contentTopic: string,
7878
public ephemeral: boolean = false,
79-
public pubsubTopic: PubSubTopic,
79+
public pubsubTopic: PubsubTopic,
8080
public metaSetter?: IMetaSetter
8181
) {
8282
if (!contentTopic || contentTopic === "") {
@@ -119,7 +119,7 @@ export class Encoder implements IEncoder {
119119
* messages.
120120
*/
121121
export function createEncoder({
122-
pubsubTopic = DefaultPubSubTopic,
122+
pubsubTopic = DefaultPubsubTopic,
123123
contentTopic,
124124
ephemeral,
125125
metaSetter
@@ -129,7 +129,7 @@ export function createEncoder({
129129

130130
export class Decoder implements IDecoder<DecodedMessage> {
131131
constructor(
132-
public pubsubTopic: PubSubTopic,
132+
public pubsubTopic: PubsubTopic,
133133
public contentTopic: string
134134
) {
135135
if (!contentTopic || contentTopic === "") {
@@ -182,7 +182,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
182182
*/
183183
export function createDecoder(
184184
contentTopic: string,
185-
pubsubTopic: PubSubTopic = DefaultPubSubTopic
185+
pubsubTopic: PubsubTopic = DefaultPubsubTopic
186186
): Decoder {
187187
return new Decoder(pubsubTopic, contentTopic);
188188
}

packages/core/src/lib/store/index.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
IStore,
88
Libp2p,
99
ProtocolCreateOptions,
10-
PubSubTopic
10+
PubsubTopic
1111
} from "@waku/interfaces";
1212
import { proto_store as proto } from "@waku/proto";
1313
import { ensurePubsubTopicIsConfigured, isDefined } from "@waku/utils";
@@ -19,7 +19,7 @@ import { pipe } from "it-pipe";
1919
import { Uint8ArrayList } from "uint8arraylist";
2020

2121
import { BaseProtocol } from "../base_protocol.js";
22-
import { DefaultPubSubTopic } from "../constants.js";
22+
import { DefaultPubsubTopic } from "../constants.js";
2323
import { toProtoMessage } from "../to_proto_message.js";
2424

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

8181
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
8282
super(StoreCodec, libp2p.components);
83-
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic];
83+
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubsubTopic];
8484
}
8585

8686
/**
@@ -230,29 +230,29 @@ class Store extends BaseProtocol implements IStore {
230230
}
231231

232232
// convert array to set to remove duplicates
233-
const uniquePubSubTopicsInQuery = Array.from(
233+
const uniquePubsubTopicsInQuery = Array.from(
234234
new Set(decoders.map((decoder) => decoder.pubsubTopic))
235235
);
236236

237237
// If multiple pubsub topics are provided, throw an error
238-
if (uniquePubSubTopicsInQuery.length > 1) {
238+
if (uniquePubsubTopicsInQuery.length > 1) {
239239
throw new Error(
240240
"API does not support querying multiple pubsub topics at once"
241241
);
242242
}
243243

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

247-
ensurePubsubTopicIsConfigured(pubSubTopicForQuery, this.pubsubTopics);
247+
ensurePubsubTopicIsConfigured(pubsubTopicForQuery, this.pubsubTopics);
248248

249249
// check that the pubsubTopic from the Cursor and Decoder match
250250
if (
251251
options?.cursor?.pubsubTopic &&
252-
options.cursor.pubsubTopic !== pubSubTopicForQuery
252+
options.cursor.pubsubTopic !== pubsubTopicForQuery
253253
) {
254254
throw new Error(
255-
`Cursor pubsub topic (${options?.cursor?.pubsubTopic}) does not match decoder pubsub topic (${pubSubTopicForQuery})`
255+
`Cursor pubsub topic (${options?.cursor?.pubsubTopic}) does not match decoder pubsub topic (${pubsubTopicForQuery})`
256256
);
257257
}
258258

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

269269
const contentTopics = decoders
270-
.filter((decoder) => decoder.pubsubTopic === pubSubTopicForQuery)
270+
.filter((decoder) => decoder.pubsubTopic === pubsubTopicForQuery)
271271
.map((dec) => dec.contentTopic);
272272

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

277277
const queryOpts = Object.assign(
278278
{
279-
pubsubTopic: pubSubTopicForQuery,
279+
pubsubTopic: pubsubTopicForQuery,
280280
pageDirection: PageDirection.BACKWARD,
281281
pageSize: DefaultPageSize
282282
},

packages/core/src/lib/waku.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
IRelay,
88
IStore,
99
Libp2p,
10-
PubSubTopic,
10+
PubsubTopic,
1111
Waku
1212
} from "@waku/interfaces";
1313
import { Protocols } from "@waku/interfaces";
@@ -53,7 +53,7 @@ export class WakuNode implements Waku {
5353

5454
constructor(
5555
options: WakuOptions,
56-
public readonly pubsubTopics: PubSubTopic[],
56+
public readonly pubsubTopics: PubsubTopic[],
5757
libp2p: Libp2p,
5858
store?: (libp2p: Libp2p) => IStore,
5959
lightPush?: (libp2p: Libp2p) => ILightPush,

0 commit comments

Comments
 (0)