mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-11 13:04:41 +00:00
chore: use pubsubTopic
/pubsubTopics
across the codebase (#1653)
* chore: change all references of pubSubTopic to pubsubTopic * change references of pubSubTopics to pubsubTopics * flag words in cspell
This commit is contained in:
parent
b96c3bd3e1
commit
9fe04d85f3
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.1",
|
||||
"version": "0.2",
|
||||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
|
||||
"language": "en",
|
||||
"words": [
|
||||
@ -123,7 +123,7 @@
|
||||
"Привет",
|
||||
"مرحبا"
|
||||
],
|
||||
"flagWords": [],
|
||||
"flagWords": ["pubSub", "pubSubTopics", "pubSubTopic"],
|
||||
"ignorePaths": [
|
||||
"package.json",
|
||||
"package-lock.json",
|
||||
|
@ -45,7 +45,7 @@ export class ConnectionManager
|
||||
peerId: string,
|
||||
libp2p: Libp2p,
|
||||
keepAliveOptions: KeepAliveOptions,
|
||||
pubSubTopics: PubSubTopic[],
|
||||
pubsubTopics: PubSubTopic[],
|
||||
relay?: IRelay,
|
||||
options?: ConnectionManagerOptions
|
||||
): ConnectionManager {
|
||||
@ -54,7 +54,7 @@ export class ConnectionManager
|
||||
instance = new ConnectionManager(
|
||||
libp2p,
|
||||
keepAliveOptions,
|
||||
pubSubTopics,
|
||||
pubsubTopics,
|
||||
relay,
|
||||
options
|
||||
);
|
||||
@ -500,9 +500,9 @@ 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) =>
|
||||
const isTopicConfigured = pubsubTopics.some((topic) =>
|
||||
this.configuredPubSubTopics.includes(topic)
|
||||
);
|
||||
return isTopicConfigured;
|
||||
|
@ -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<
|
||||
@ -59,12 +59,12 @@ class Subscription {
|
||||
>;
|
||||
|
||||
constructor(
|
||||
pubSubTopic: PubSubTopic,
|
||||
pubsubTopic: PubSubTopic,
|
||||
remotePeer: Peer,
|
||||
newStream: (peer: Peer) => Promise<Stream>
|
||||
) {
|
||||
this.peer = remotePeer;
|
||||
this.pubSubTopic = pubSubTopic;
|
||||
this.pubsubTopic = pubsubTopic;
|
||||
this.newStream = newStream;
|
||||
this.subscriptionCallbacks = new Map();
|
||||
}
|
||||
@ -80,7 +80,7 @@ class Subscription {
|
||||
const stream = await this.newStream(this.peer);
|
||||
|
||||
const request = FilterSubscribeRpc.createSubscribeRequest(
|
||||
this.pubSubTopic,
|
||||
this.pubsubTopic,
|
||||
contentTopics
|
||||
);
|
||||
|
||||
@ -145,7 +145,7 @@ class Subscription {
|
||||
async unsubscribe(contentTopics: ContentTopic[]): Promise<void> {
|
||||
const stream = await this.newStream(this.peer);
|
||||
const unsubscribeRequest = FilterSubscribeRpc.createUnsubscribeRequest(
|
||||
this.pubSubTopic,
|
||||
this.pubsubTopic,
|
||||
contentTopics
|
||||
);
|
||||
|
||||
@ -194,7 +194,7 @@ class Subscription {
|
||||
const stream = await this.newStream(this.peer);
|
||||
|
||||
const request = FilterSubscribeRpc.createUnsubscribeAllRequest(
|
||||
this.pubSubTopic
|
||||
this.pubsubTopic
|
||||
);
|
||||
|
||||
try {
|
||||
@ -229,35 +229,35 @@ class Subscription {
|
||||
log("No subscription callback available for ", contentTopic);
|
||||
return;
|
||||
}
|
||||
await pushMessage(subscriptionCallback, this.pubSubTopic, message);
|
||||
await pushMessage(subscriptionCallback, this.pubsubTopic, message);
|
||||
}
|
||||
}
|
||||
|
||||
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}`);
|
||||
return this.activeSubscriptions.get(`${pubsubTopic}_${peerIdStr}`);
|
||||
}
|
||||
|
||||
private setActiveSubscription(
|
||||
pubSubTopic: PubSubTopic,
|
||||
pubsubTopic: PubSubTopic,
|
||||
peerIdStr: PeerIdStr,
|
||||
subscription: Subscription
|
||||
): Subscription {
|
||||
this.activeSubscriptions.set(`${pubSubTopic}_${peerIdStr}`, subscription);
|
||||
this.activeSubscriptions.set(`${pubsubTopic}_${peerIdStr}`, subscription);
|
||||
return subscription;
|
||||
}
|
||||
|
||||
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("Failed to register ", FilterCodecs.PUSH, e);
|
||||
@ -267,9 +267,9 @@ class Filter extends BaseProtocol implements IReceiver {
|
||||
}
|
||||
|
||||
async createSubscription(
|
||||
pubSubTopic: string = DefaultPubSubTopic
|
||||
pubsubTopic: string = DefaultPubSubTopic
|
||||
): Promise<Subscription> {
|
||||
ensurePubsubTopicIsConfigured(pubSubTopic, this.pubSubTopics);
|
||||
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
|
||||
|
||||
//TODO: get a relevant peer for the topic/shard
|
||||
// https://github.com/waku-org/js-waku/pull/1586#discussion_r1336428230
|
||||
@ -281,11 +281,11 @@ class Filter extends BaseProtocol implements IReceiver {
|
||||
)[0];
|
||||
|
||||
const subscription =
|
||||
this.getActiveSubscription(pubSubTopic, peer.id.toString()) ??
|
||||
this.getActiveSubscription(pubsubTopic, peer.id.toString()) ??
|
||||
this.setActiveSubscription(
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
peer.id.toString(),
|
||||
new Subscription(pubSubTopic, peer, this.getStream.bind(this, peer))
|
||||
new Subscription(pubsubTopic, peer, this.getStream.bind(this, peer))
|
||||
);
|
||||
|
||||
return subscription;
|
||||
@ -385,7 +385,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;
|
||||
@ -399,7 +399,7 @@ async function pushMessage<T extends IDecodedMessage>(
|
||||
try {
|
||||
const decodePromises = decoders.map((dec) =>
|
||||
dec
|
||||
.fromProtoObj(pubSubTopic, message as IProtoMessage)
|
||||
.fromProtoObj(pubsubTopic, message as IProtoMessage)
|
||||
.then((decoded) => decoded || Promise.reject("Decoding failed"))
|
||||
);
|
||||
|
||||
|
@ -118,12 +118,12 @@ export class KeepAliveManager {
|
||||
): NodeJS.Timeout[] {
|
||||
// send a ping message to each PubSubTopic the peer is part of
|
||||
const intervals: NodeJS.Timeout[] = [];
|
||||
for (const topic of relay.pubSubTopics) {
|
||||
for (const topic of relay.pubsubTopics) {
|
||||
const meshPeers = relay.getMeshPeers(topic);
|
||||
if (!meshPeers.includes(peerIdStr)) continue;
|
||||
|
||||
const encoder = createEncoder({
|
||||
pubSubTopic: topic,
|
||||
pubsubTopic: topic,
|
||||
contentTopic: RelayPingContentTopic,
|
||||
ephemeral: true
|
||||
});
|
||||
|
@ -42,18 +42,18 @@ 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(
|
||||
encoder: IEncoder,
|
||||
message: IMessage,
|
||||
pubSubTopic: string
|
||||
pubsubTopic: string
|
||||
): Promise<PreparePushMessageResult> {
|
||||
try {
|
||||
if (!isSizeValid(message.payload)) {
|
||||
@ -70,7 +70,7 @@ class LightPush extends BaseProtocol implements ILightPush {
|
||||
};
|
||||
}
|
||||
|
||||
const query = PushRpc.createRequest(protoMessage, pubSubTopic);
|
||||
const query = PushRpc.createRequest(protoMessage, pubsubTopic);
|
||||
return { query, error: null };
|
||||
} catch (error) {
|
||||
log("Failed to prepare push message", error);
|
||||
@ -83,15 +83,15 @@ class LightPush extends BaseProtocol implements ILightPush {
|
||||
}
|
||||
|
||||
async send(encoder: IEncoder, message: IMessage): Promise<SendResult> {
|
||||
const { pubSubTopic } = encoder;
|
||||
ensurePubsubTopicIsConfigured(pubSubTopic, this.pubSubTopics);
|
||||
const { pubsubTopic } = encoder;
|
||||
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
|
||||
|
||||
const recipients: PeerId[] = [];
|
||||
|
||||
const { query, error: preparationError } = await this.preparePushMessage(
|
||||
encoder,
|
||||
message,
|
||||
pubSubTopic
|
||||
pubsubTopic
|
||||
);
|
||||
|
||||
if (preparationError || !query) {
|
||||
|
@ -7,13 +7,13 @@ export class PushRpc {
|
||||
|
||||
static createRequest(
|
||||
message: proto.WakuMessage,
|
||||
pubSubTopic: string
|
||||
pubsubTopic: string
|
||||
): PushRpc {
|
||||
return new PushRpc({
|
||||
requestId: uuid(),
|
||||
request: {
|
||||
message: message,
|
||||
pubsubTopic: pubSubTopic
|
||||
pubsubTopic: pubsubTopic
|
||||
},
|
||||
response: undefined
|
||||
});
|
||||
|
@ -11,7 +11,7 @@ describe("Waku Message version 0", function () {
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.uint8Array({ minLength: 1 }),
|
||||
async (contentTopic, pubSubTopic, payload) => {
|
||||
async (contentTopic, pubsubTopic, payload) => {
|
||||
const encoder = createEncoder({
|
||||
contentTopic
|
||||
});
|
||||
@ -19,12 +19,12 @@ describe("Waku Message version 0", function () {
|
||||
const decoder = createDecoder(contentTopic);
|
||||
const protoResult = await decoder.fromWireToProtoObj(bytes);
|
||||
const result = (await decoder.fromProtoObj(
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
protoResult!
|
||||
)) as DecodedMessage;
|
||||
|
||||
expect(result.contentTopic).to.eq(contentTopic);
|
||||
expect(result.pubSubTopic).to.eq(pubSubTopic);
|
||||
expect(result.pubsubTopic).to.eq(pubsubTopic);
|
||||
expect(result.version).to.eq(0);
|
||||
expect(result.ephemeral).to.be.false;
|
||||
expect(result.payload).to.deep.eq(payload);
|
||||
@ -40,7 +40,7 @@ describe("Waku Message version 0", function () {
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.uint8Array({ minLength: 1 }),
|
||||
async (contentTopic, pubSubTopic, payload) => {
|
||||
async (contentTopic, pubsubTopic, payload) => {
|
||||
const encoder = createEncoder({
|
||||
contentTopic,
|
||||
ephemeral: true
|
||||
@ -49,7 +49,7 @@ describe("Waku Message version 0", function () {
|
||||
const decoder = createDecoder(contentTopic);
|
||||
const protoResult = await decoder.fromWireToProtoObj(bytes);
|
||||
const result = (await decoder.fromProtoObj(
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
protoResult!
|
||||
)) as DecodedMessage;
|
||||
|
||||
@ -65,7 +65,7 @@ describe("Waku Message version 0", function () {
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.uint8Array({ minLength: 1 }),
|
||||
async (contentTopic, pubSubTopic, payload) => {
|
||||
async (contentTopic, pubsubTopic, payload) => {
|
||||
// Encode the length of the payload
|
||||
// Not a relevant real life example
|
||||
const metaSetter = (
|
||||
@ -86,7 +86,7 @@ describe("Waku Message version 0", function () {
|
||||
const decoder = createDecoder(contentTopic);
|
||||
const protoResult = await decoder.fromWireToProtoObj(bytes);
|
||||
const result = (await decoder.fromProtoObj(
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
protoResult!
|
||||
)) as DecodedMessage;
|
||||
|
||||
|
@ -22,7 +22,7 @@ export { proto };
|
||||
|
||||
export class DecodedMessage implements IDecodedMessage {
|
||||
constructor(
|
||||
public pubSubTopic: string,
|
||||
public pubsubTopic: string,
|
||||
protected proto: proto.WakuMessage
|
||||
) {}
|
||||
|
||||
@ -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 === "") {
|
||||
@ -119,17 +119,17 @@ export class Encoder implements IEncoder {
|
||||
* messages.
|
||||
*/
|
||||
export function createEncoder({
|
||||
pubSubTopic = DefaultPubSubTopic,
|
||||
pubsubTopic = DefaultPubSubTopic,
|
||||
contentTopic,
|
||||
ephemeral,
|
||||
metaSetter
|
||||
}: EncoderOptions): Encoder {
|
||||
return new Encoder(contentTopic, ephemeral, pubSubTopic, metaSetter);
|
||||
return new Encoder(contentTopic, ephemeral, pubsubTopic, metaSetter);
|
||||
}
|
||||
|
||||
export class Decoder implements IDecoder<DecodedMessage> {
|
||||
constructor(
|
||||
public pubSubTopic: PubSubTopic,
|
||||
public pubsubTopic: PubSubTopic,
|
||||
public contentTopic: string
|
||||
) {
|
||||
if (!contentTopic || contentTopic === "") {
|
||||
@ -152,7 +152,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
||||
}
|
||||
|
||||
async fromProtoObj(
|
||||
pubSubTopic: string,
|
||||
pubsubTopic: string,
|
||||
proto: IProtoMessage
|
||||
): Promise<DecodedMessage | undefined> {
|
||||
// https://rfc.vac.dev/spec/14/
|
||||
@ -167,7 +167,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
return new DecodedMessage(pubSubTopic, proto);
|
||||
return new DecodedMessage(pubsubTopic, proto);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ export enum PageDirection {
|
||||
|
||||
export interface Params {
|
||||
contentTopics: string[];
|
||||
pubSubTopic: string;
|
||||
pubsubTopic: string;
|
||||
pageDirection: PageDirection;
|
||||
pageSize: number;
|
||||
startTime?: Date;
|
||||
@ -59,7 +59,7 @@ export class HistoryRpc {
|
||||
return new HistoryRpc({
|
||||
requestId: uuid(),
|
||||
query: {
|
||||
pubsubTopic: params.pubSubTopic,
|
||||
pubsubTopic: params.pubsubTopic,
|
||||
contentFilters,
|
||||
pagingInfo,
|
||||
startTime,
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -231,7 +231,7 @@ class Store extends BaseProtocol implements IStore {
|
||||
|
||||
// convert array to set to remove duplicates
|
||||
const uniquePubSubTopicsInQuery = Array.from(
|
||||
new Set(decoders.map((decoder) => decoder.pubSubTopic))
|
||||
new Set(decoders.map((decoder) => decoder.pubsubTopic))
|
||||
);
|
||||
|
||||
// If multiple pubsub topics are provided, throw an error
|
||||
@ -244,9 +244,9 @@ class Store extends BaseProtocol implements IStore {
|
||||
// we can be certain that there is only one pubsub topic in the query
|
||||
const pubSubTopicForQuery = uniquePubSubTopicsInQuery[0];
|
||||
|
||||
ensurePubsubTopicIsConfigured(pubSubTopicForQuery, this.pubSubTopics);
|
||||
ensurePubsubTopicIsConfigured(pubSubTopicForQuery, this.pubsubTopics);
|
||||
|
||||
// check that the pubSubTopic from the Cursor and Decoder match
|
||||
// check that the pubsubTopic from the Cursor and Decoder match
|
||||
if (
|
||||
options?.cursor?.pubsubTopic &&
|
||||
options.cursor.pubsubTopic !== pubSubTopicForQuery
|
||||
@ -267,7 +267,7 @@ 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) {
|
||||
@ -276,7 +276,7 @@ class Store extends BaseProtocol implements IStore {
|
||||
|
||||
const queryOpts = Object.assign(
|
||||
{
|
||||
pubSubTopic: pubSubTopicForQuery,
|
||||
pubsubTopic: pubSubTopicForQuery,
|
||||
pageDirection: PageDirection.BACKWARD,
|
||||
pageSize: DefaultPageSize
|
||||
},
|
||||
@ -327,7 +327,7 @@ async function* paginate<T extends IDecodedMessage>(
|
||||
|
||||
log(
|
||||
"Querying store peer",
|
||||
`for (${queryOpts.pubSubTopic})`,
|
||||
`for (${queryOpts.pubsubTopic})`,
|
||||
queryOpts.contentTopics
|
||||
);
|
||||
|
||||
@ -374,7 +374,7 @@ async function* paginate<T extends IDecodedMessage>(
|
||||
const decoder = decoders.get(contentTopic);
|
||||
if (decoder) {
|
||||
return decoder.fromProtoObj(
|
||||
queryOpts.pubSubTopic,
|
||||
queryOpts.pubsubTopic,
|
||||
toProtoMessage(protoMsg)
|
||||
);
|
||||
}
|
||||
@ -425,7 +425,7 @@ export async function createCursor(message: IDecodedMessage): Promise<Cursor> {
|
||||
|
||||
return {
|
||||
digest,
|
||||
pubsubTopic: message.pubSubTopic,
|
||||
pubsubTopic: message.pubsubTopic,
|
||||
senderTime: messageTime,
|
||||
receiverTime: messageTime
|
||||
};
|
||||
|
@ -97,13 +97,13 @@ async function waitForConnectedPeer(protocol: IBaseProtocol): Promise<void> {
|
||||
|
||||
/**
|
||||
* Wait for at least one peer with the given protocol to be connected and in the gossipsub
|
||||
* mesh for all pubSubTopics.
|
||||
* mesh for all pubsubTopics.
|
||||
*/
|
||||
async function waitForGossipSubPeerInMesh(waku: IRelay): Promise<void> {
|
||||
let peers = waku.getMeshPeers();
|
||||
const pubSubTopics = waku.pubSubTopics;
|
||||
const pubsubTopics = waku.pubsubTopics;
|
||||
|
||||
for (const topic of pubSubTopics) {
|
||||
for (const topic of pubsubTopics) {
|
||||
while (peers.length == 0) {
|
||||
await pEvent(waku.gossipSub, "gossipsub:heartbeat");
|
||||
peers = waku.getMeshPeers(topic);
|
||||
|
@ -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,
|
||||
@ -88,7 +88,7 @@ export class WakuNode implements Waku {
|
||||
peerId,
|
||||
libp2p,
|
||||
{ pingKeepAlive, relayKeepAlive },
|
||||
pubSubTopics,
|
||||
pubsubTopics,
|
||||
this.relay
|
||||
);
|
||||
|
||||
|
@ -25,7 +25,7 @@ export interface IFilterSubscription {
|
||||
export type IFilter = IReceiver &
|
||||
IBaseProtocol & {
|
||||
createSubscription(
|
||||
pubSubTopic?: string,
|
||||
pubsubTopic?: string,
|
||||
peerId?: PeerId
|
||||
): Promise<IFilterSubscription>;
|
||||
};
|
||||
|
@ -38,7 +38,7 @@ export interface IMetaSetter {
|
||||
}
|
||||
|
||||
export interface EncoderOptions {
|
||||
pubSubTopic?: PubSubTopic;
|
||||
pubsubTopic?: PubSubTopic;
|
||||
/** The content topic to set on outgoing messages. */
|
||||
contentTopic: string;
|
||||
/**
|
||||
@ -55,7 +55,7 @@ export interface EncoderOptions {
|
||||
}
|
||||
|
||||
export interface IEncoder {
|
||||
pubSubTopic: PubSubTopic;
|
||||
pubsubTopic: PubSubTopic;
|
||||
contentTopic: string;
|
||||
ephemeral: boolean;
|
||||
toWire: (message: IMessage) => Promise<Uint8Array | undefined>;
|
||||
@ -65,7 +65,7 @@ export interface IEncoder {
|
||||
export interface IDecodedMessage {
|
||||
payload: Uint8Array;
|
||||
contentTopic: string;
|
||||
pubSubTopic: PubSubTopic;
|
||||
pubsubTopic: PubSubTopic;
|
||||
timestamp: Date | undefined;
|
||||
rateLimitProof: IRateLimitProof | undefined;
|
||||
ephemeral: boolean | undefined;
|
||||
@ -73,11 +73,11 @@ export interface IDecodedMessage {
|
||||
}
|
||||
|
||||
export interface IDecoder<T extends IDecodedMessage> {
|
||||
pubSubTopic: PubSubTopic;
|
||||
pubsubTopic: PubSubTopic;
|
||||
contentTopic: string;
|
||||
fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>;
|
||||
fromProtoObj: (
|
||||
pubSubTopic: string,
|
||||
pubsubTopic: string,
|
||||
proto: IProtoMessage
|
||||
) => Promise<T | undefined>;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ export type ProtocolCreateOptions = {
|
||||
* See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details.
|
||||
*
|
||||
*/
|
||||
pubSubTopics?: PubSubTopic[];
|
||||
pubsubTopics?: PubSubTopic[];
|
||||
/**
|
||||
* You can pass options to the `Libp2p` instance used by {@link @waku/core!WakuNode} using the `libp2p` property.
|
||||
* This property is the same type as the one passed to [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
|
||||
|
@ -13,7 +13,7 @@ import type { ISender } from "./sender.js";
|
||||
* @property getMeshPeers - Function to retrieve the mesh peers for a given topic or all topics if none is specified. Returns an array of peer IDs as strings.
|
||||
*/
|
||||
export interface IRelayAPI {
|
||||
readonly pubSubTopics: Set<PubSubTopic>;
|
||||
readonly pubsubTopics: Set<PubSubTopic>;
|
||||
readonly gossipSub: GossipSub;
|
||||
start: () => Promise<void>;
|
||||
getMeshPeers: (topic?: TopicStr) => PeerIdStr[];
|
||||
|
@ -11,13 +11,13 @@ export class DecodedMessage
|
||||
private readonly _decodedPayload: Uint8Array;
|
||||
|
||||
constructor(
|
||||
pubSubTopic: string,
|
||||
pubsubTopic: string,
|
||||
proto: proto.WakuMessage,
|
||||
decodedPayload: Uint8Array,
|
||||
public signature?: Uint8Array,
|
||||
public signaturePublicKey?: Uint8Array
|
||||
) {
|
||||
super(pubSubTopic, proto);
|
||||
super(pubsubTopic, proto);
|
||||
this._decodedPayload = decodedPayload;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ describe("Ecies Encryption", function () {
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.uint8Array({ minLength: 1 }),
|
||||
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
|
||||
async (pubSubTopic, contentTopic, payload, privateKey) => {
|
||||
async (pubsubTopic, contentTopic, payload, privateKey) => {
|
||||
const publicKey = getPublicKey(privateKey);
|
||||
|
||||
const encoder = createEncoder({
|
||||
@ -25,11 +25,11 @@ describe("Ecies Encryption", function () {
|
||||
const decoder = createDecoder(contentTopic, privateKey);
|
||||
const protoResult = await decoder.fromWireToProtoObj(bytes!);
|
||||
if (!protoResult) throw "Failed to proto decode";
|
||||
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
|
||||
const result = await decoder.fromProtoObj(pubsubTopic, protoResult);
|
||||
if (!result) throw "Failed to decode";
|
||||
|
||||
expect(result.contentTopic).to.equal(contentTopic);
|
||||
expect(result.pubSubTopic).to.equal(pubSubTopic);
|
||||
expect(result.pubsubTopic).to.equal(pubsubTopic);
|
||||
expect(result.version).to.equal(1);
|
||||
expect(result?.payload).to.deep.equal(payload);
|
||||
expect(result.signature).to.be.undefined;
|
||||
@ -50,7 +50,7 @@ describe("Ecies Encryption", function () {
|
||||
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
|
||||
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
|
||||
async (
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
contentTopic,
|
||||
payload,
|
||||
alicePrivateKey,
|
||||
@ -69,11 +69,11 @@ describe("Ecies Encryption", function () {
|
||||
const decoder = createDecoder(contentTopic, bobPrivateKey);
|
||||
const protoResult = await decoder.fromWireToProtoObj(bytes!);
|
||||
if (!protoResult) throw "Failed to proto decode";
|
||||
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
|
||||
const result = await decoder.fromProtoObj(pubsubTopic, protoResult);
|
||||
if (!result) throw "Failed to decode";
|
||||
|
||||
expect(result.contentTopic).to.equal(contentTopic);
|
||||
expect(result.pubSubTopic).to.equal(pubSubTopic);
|
||||
expect(result.pubsubTopic).to.equal(pubsubTopic);
|
||||
expect(result.version).to.equal(1);
|
||||
expect(result?.payload).to.deep.equal(payload);
|
||||
expect(result.signature).to.not.be.undefined;
|
||||
@ -90,7 +90,7 @@ describe("Ecies Encryption", function () {
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.uint8Array({ minLength: 1 }),
|
||||
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
|
||||
async (pubSubTopic, contentTopic, payload, privateKey) => {
|
||||
async (pubsubTopic, contentTopic, payload, privateKey) => {
|
||||
const publicKey = getPublicKey(privateKey);
|
||||
const metaSetter = (
|
||||
msg: IProtoMessage & { meta: undefined }
|
||||
@ -111,7 +111,7 @@ describe("Ecies Encryption", function () {
|
||||
const decoder = createDecoder(contentTopic, privateKey);
|
||||
const protoResult = await decoder.fromWireToProtoObj(bytes!);
|
||||
if (!protoResult) throw "Failed to proto decode";
|
||||
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
|
||||
const result = await decoder.fromProtoObj(pubsubTopic, protoResult);
|
||||
if (!result) throw "Failed to decode";
|
||||
|
||||
const expectedMeta = metaSetter({
|
||||
|
@ -33,7 +33,7 @@ const log = debug("waku:message-encryption:ecies");
|
||||
|
||||
class Encoder implements IEncoder {
|
||||
constructor(
|
||||
public pubSubTopic: PubSubTopic,
|
||||
public pubsubTopic: PubSubTopic,
|
||||
public contentTopic: string,
|
||||
private publicKey: Uint8Array,
|
||||
private sigPrivKey?: Uint8Array,
|
||||
@ -97,7 +97,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
||||
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
||||
*/
|
||||
export function createEncoder({
|
||||
pubSubTopic = DefaultPubSubTopic,
|
||||
pubsubTopic = DefaultPubSubTopic,
|
||||
contentTopic,
|
||||
publicKey,
|
||||
sigPrivKey,
|
||||
@ -105,7 +105,7 @@ export function createEncoder({
|
||||
metaSetter
|
||||
}: EncoderOptions): Encoder {
|
||||
return new Encoder(
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
contentTopic,
|
||||
publicKey,
|
||||
sigPrivKey,
|
||||
@ -116,15 +116,15 @@ export function createEncoder({
|
||||
|
||||
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
constructor(
|
||||
pubSubTopic: PubSubTopic,
|
||||
pubsubTopic: PubSubTopic,
|
||||
contentTopic: string,
|
||||
private privateKey: Uint8Array
|
||||
) {
|
||||
super(pubSubTopic, contentTopic);
|
||||
super(pubsubTopic, contentTopic);
|
||||
}
|
||||
|
||||
async fromProtoObj(
|
||||
pubSubTopic: string,
|
||||
pubsubTopic: string,
|
||||
protoMessage: IProtoMessage
|
||||
): Promise<DecodedMessage | undefined> {
|
||||
const cipherPayload = protoMessage.payload;
|
||||
@ -165,7 +165,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
|
||||
log("Message decrypted", protoMessage);
|
||||
return new DecodedMessage(
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
protoMessage,
|
||||
res.payload,
|
||||
res.sig?.signature,
|
||||
@ -189,7 +189,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
export function createDecoder(
|
||||
contentTopic: string,
|
||||
privateKey: Uint8Array,
|
||||
pubSubTopic: PubSubTopic = DefaultPubSubTopic
|
||||
pubsubTopic: PubSubTopic = DefaultPubSubTopic
|
||||
): Decoder {
|
||||
return new Decoder(pubSubTopic, contentTopic, privateKey);
|
||||
return new Decoder(pubsubTopic, contentTopic, privateKey);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ describe("Symmetric Encryption", function () {
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.uint8Array({ minLength: 1 }),
|
||||
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
|
||||
async (pubSubTopic, contentTopic, payload, symKey) => {
|
||||
async (pubsubTopic, contentTopic, payload, symKey) => {
|
||||
const encoder = createEncoder({
|
||||
contentTopic,
|
||||
symKey
|
||||
@ -23,11 +23,11 @@ describe("Symmetric Encryption", function () {
|
||||
const decoder = createDecoder(contentTopic, symKey);
|
||||
const protoResult = await decoder.fromWireToProtoObj(bytes!);
|
||||
if (!protoResult) throw "Failed to proto decode";
|
||||
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
|
||||
const result = await decoder.fromProtoObj(pubsubTopic, protoResult);
|
||||
if (!result) throw "Failed to decode";
|
||||
|
||||
expect(result.contentTopic).to.equal(contentTopic);
|
||||
expect(result.pubSubTopic).to.equal(pubSubTopic);
|
||||
expect(result.pubsubTopic).to.equal(pubsubTopic);
|
||||
expect(result.version).to.equal(1);
|
||||
expect(result?.payload).to.deep.equal(payload);
|
||||
expect(result.signature).to.be.undefined;
|
||||
@ -45,7 +45,7 @@ describe("Symmetric Encryption", function () {
|
||||
fc.uint8Array({ minLength: 1 }),
|
||||
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
|
||||
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
|
||||
async (pubSubTopic, contentTopic, payload, sigPrivKey, symKey) => {
|
||||
async (pubsubTopic, contentTopic, payload, sigPrivKey, symKey) => {
|
||||
const sigPubKey = getPublicKey(sigPrivKey);
|
||||
|
||||
const encoder = createEncoder({
|
||||
@ -58,11 +58,11 @@ describe("Symmetric Encryption", function () {
|
||||
const decoder = createDecoder(contentTopic, symKey);
|
||||
const protoResult = await decoder.fromWireToProtoObj(bytes!);
|
||||
if (!protoResult) throw "Failed to proto decode";
|
||||
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
|
||||
const result = await decoder.fromProtoObj(pubsubTopic, protoResult);
|
||||
if (!result) throw "Failed to decode";
|
||||
|
||||
expect(result.contentTopic).to.equal(contentTopic);
|
||||
expect(result.pubSubTopic).to.equal(pubSubTopic);
|
||||
expect(result.pubsubTopic).to.equal(pubsubTopic);
|
||||
expect(result.version).to.equal(1);
|
||||
expect(result?.payload).to.deep.equal(payload);
|
||||
expect(result.signature).to.not.be.undefined;
|
||||
@ -79,7 +79,7 @@ describe("Symmetric Encryption", function () {
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.uint8Array({ minLength: 1 }),
|
||||
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
|
||||
async (pubSubTopic, contentTopic, payload, symKey) => {
|
||||
async (pubsubTopic, contentTopic, payload, symKey) => {
|
||||
const metaSetter = (
|
||||
msg: IProtoMessage & { meta: undefined }
|
||||
): Uint8Array => {
|
||||
@ -99,7 +99,7 @@ describe("Symmetric Encryption", function () {
|
||||
const decoder = createDecoder(contentTopic, symKey);
|
||||
const protoResult = await decoder.fromWireToProtoObj(bytes!);
|
||||
if (!protoResult) throw "Failed to proto decode";
|
||||
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
|
||||
const result = await decoder.fromProtoObj(pubsubTopic, protoResult);
|
||||
if (!result) throw "Failed to decode";
|
||||
|
||||
const expectedMeta = metaSetter({
|
||||
|
@ -29,7 +29,7 @@ const log = debug("waku:message-encryption:symmetric");
|
||||
|
||||
class Encoder implements IEncoder {
|
||||
constructor(
|
||||
public pubSubTopic: PubSubTopic,
|
||||
public pubsubTopic: PubSubTopic,
|
||||
public contentTopic: string,
|
||||
private symKey: Uint8Array,
|
||||
private sigPrivKey?: Uint8Array,
|
||||
@ -93,7 +93,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
||||
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
||||
*/
|
||||
export function createEncoder({
|
||||
pubSubTopic = DefaultPubSubTopic,
|
||||
pubsubTopic = DefaultPubSubTopic,
|
||||
contentTopic,
|
||||
symKey,
|
||||
sigPrivKey,
|
||||
@ -101,7 +101,7 @@ export function createEncoder({
|
||||
metaSetter
|
||||
}: EncoderOptions): Encoder {
|
||||
return new Encoder(
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
contentTopic,
|
||||
symKey,
|
||||
sigPrivKey,
|
||||
@ -112,15 +112,15 @@ export function createEncoder({
|
||||
|
||||
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
constructor(
|
||||
pubSubTopic: PubSubTopic,
|
||||
pubsubTopic: PubSubTopic,
|
||||
contentTopic: string,
|
||||
private symKey: Uint8Array
|
||||
) {
|
||||
super(pubSubTopic, contentTopic);
|
||||
super(pubsubTopic, contentTopic);
|
||||
}
|
||||
|
||||
async fromProtoObj(
|
||||
pubSubTopic: string,
|
||||
pubsubTopic: string,
|
||||
protoMessage: IProtoMessage
|
||||
): Promise<DecodedMessage | undefined> {
|
||||
const cipherPayload = protoMessage.payload;
|
||||
@ -161,7 +161,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
|
||||
log("Message decrypted", protoMessage);
|
||||
return new DecodedMessage(
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
protoMessage,
|
||||
res.payload,
|
||||
res.sig?.signature,
|
||||
@ -185,7 +185,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
export function createDecoder(
|
||||
contentTopic: string,
|
||||
symKey: Uint8Array,
|
||||
pubSubTopic: PubSubTopic = DefaultPubSubTopic
|
||||
pubsubTopic: PubSubTopic = DefaultPubSubTopic
|
||||
): Decoder {
|
||||
return new Decoder(pubSubTopic, contentTopic, symKey);
|
||||
return new Decoder(pubsubTopic, contentTopic, symKey);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ describe("RFC Test Vectors", () => {
|
||||
const expectedHash =
|
||||
"4fdde1099c9f77f6dae8147b6b3179aba1fc8e14a7bf35203fc253ee479f135f";
|
||||
|
||||
const pubSubTopic = "/waku/2/default-waku/proto";
|
||||
const pubsubTopic = "/waku/2/default-waku/proto";
|
||||
const message: IProtoMessage = {
|
||||
payload: hexToBytes("0x010203045445535405060708"),
|
||||
contentTopic: "/waku/2/default-content/proto",
|
||||
@ -21,7 +21,7 @@ describe("RFC Test Vectors", () => {
|
||||
version: undefined
|
||||
};
|
||||
|
||||
const hash = messageHash(pubSubTopic, message);
|
||||
const hash = messageHash(pubsubTopic, message);
|
||||
|
||||
expect(bytesToHex(hash)).to.equal(expectedHash);
|
||||
});
|
||||
@ -30,7 +30,7 @@ describe("RFC Test Vectors", () => {
|
||||
const expectedHash =
|
||||
"87619d05e563521d9126749b45bd4cc2430df0607e77e23572d874ed9c1aaa62";
|
||||
|
||||
const pubSubTopic = "/waku/2/default-waku/proto";
|
||||
const pubsubTopic = "/waku/2/default-waku/proto";
|
||||
const message: IProtoMessage = {
|
||||
payload: hexToBytes("0x010203045445535405060708"),
|
||||
contentTopic: "/waku/2/default-content/proto",
|
||||
@ -41,7 +41,7 @@ describe("RFC Test Vectors", () => {
|
||||
version: undefined
|
||||
};
|
||||
|
||||
const hash = messageHash(pubSubTopic, message);
|
||||
const hash = messageHash(pubsubTopic, message);
|
||||
|
||||
expect(bytesToHex(hash)).to.equal(expectedHash);
|
||||
});
|
||||
@ -50,7 +50,7 @@ describe("RFC Test Vectors", () => {
|
||||
const expectedHash =
|
||||
"e1a9596237dbe2cc8aaf4b838c46a7052df6bc0d42ba214b998a8bfdbe8487d6";
|
||||
|
||||
const pubSubTopic = "/waku/2/default-waku/proto";
|
||||
const pubsubTopic = "/waku/2/default-waku/proto";
|
||||
const message: IProtoMessage = {
|
||||
payload: new Uint8Array(),
|
||||
contentTopic: "/waku/2/default-content/proto",
|
||||
@ -61,7 +61,7 @@ describe("RFC Test Vectors", () => {
|
||||
version: undefined
|
||||
};
|
||||
|
||||
const hash = messageHash(pubSubTopic, message);
|
||||
const hash = messageHash(pubsubTopic, message);
|
||||
|
||||
expect(bytesToHex(hash)).to.equal(expectedHash);
|
||||
});
|
||||
|
@ -48,7 +48,7 @@ export type ContentTopic = string;
|
||||
* Throws if libp2p.pubsub does not support Waku Relay
|
||||
*/
|
||||
class Relay implements IRelay {
|
||||
public readonly pubSubTopics: Set<PubSubTopic>;
|
||||
public readonly pubsubTopics: Set<PubSubTopic>;
|
||||
private defaultDecoder: IDecoder<IDecodedMessage>;
|
||||
|
||||
public static multicodec: string = RelayCodecs[0];
|
||||
@ -68,7 +68,7 @@ class Relay implements IRelay {
|
||||
}
|
||||
|
||||
this.gossipSub = libp2p.services.pubsub as GossipSub;
|
||||
this.pubSubTopics = new Set(options?.pubSubTopics ?? [DefaultPubSubTopic]);
|
||||
this.pubsubTopics = new Set(options?.pubsubTopics ?? [DefaultPubSubTopic]);
|
||||
|
||||
if (this.gossipSub.isStarted()) {
|
||||
this.subscribeToAllTopics();
|
||||
@ -103,8 +103,8 @@ class Relay implements IRelay {
|
||||
public async send(encoder: IEncoder, message: IMessage): Promise<SendResult> {
|
||||
const recipients: PeerId[] = [];
|
||||
|
||||
const { pubSubTopic } = encoder;
|
||||
if (!this.pubSubTopics.has(pubSubTopic)) {
|
||||
const { pubsubTopic } = encoder;
|
||||
if (!this.pubsubTopics.has(pubsubTopic)) {
|
||||
log("Failed to send waku relay: topic not configured");
|
||||
return {
|
||||
recipients,
|
||||
@ -129,7 +129,7 @@ class Relay implements IRelay {
|
||||
};
|
||||
}
|
||||
|
||||
return this.gossipSub.publish(pubSubTopic, msg);
|
||||
return this.gossipSub.publish(pubsubTopic, msg);
|
||||
}
|
||||
|
||||
public subscribe<T extends IDecodedMessage>(
|
||||
@ -139,15 +139,15 @@ class Relay implements IRelay {
|
||||
const observers: Array<[PubSubTopic, Observer<T>]> = [];
|
||||
|
||||
for (const decoder of Array.isArray(decoders) ? decoders : [decoders]) {
|
||||
const { pubSubTopic } = decoder;
|
||||
const { pubsubTopic } = decoder;
|
||||
const ctObs: Map<ContentTopic, Set<Observer<T>>> = this.observers.get(
|
||||
pubSubTopic
|
||||
pubsubTopic
|
||||
) ?? new Map();
|
||||
const observer = { pubSubTopic, decoder, callback };
|
||||
const observer = { pubsubTopic, decoder, callback };
|
||||
pushOrInitMapSet(ctObs, decoder.contentTopic, observer);
|
||||
|
||||
this.observers.set(pubSubTopic, ctObs);
|
||||
observers.push([pubSubTopic, observer]);
|
||||
this.observers.set(pubsubTopic, ctObs);
|
||||
observers.push([pubsubTopic, observer]);
|
||||
}
|
||||
|
||||
return () => {
|
||||
@ -158,8 +158,8 @@ class Relay implements IRelay {
|
||||
private removeObservers<T extends IDecodedMessage>(
|
||||
observers: Array<[PubSubTopic, Observer<T>]>
|
||||
): void {
|
||||
for (const [pubSubTopic, observer] of observers) {
|
||||
const ctObs = this.observers.get(pubSubTopic);
|
||||
for (const [pubsubTopic, observer] of observers) {
|
||||
const ctObs = this.observers.get(pubsubTopic);
|
||||
if (!ctObs) continue;
|
||||
|
||||
const contentTopic = observer.decoder.contentTopic;
|
||||
@ -168,7 +168,7 @@ class Relay implements IRelay {
|
||||
|
||||
_obs.delete(observer);
|
||||
ctObs.set(contentTopic, _obs);
|
||||
this.observers.set(pubSubTopic, ctObs);
|
||||
this.observers.set(pubsubTopic, ctObs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,8 +180,8 @@ class Relay implements IRelay {
|
||||
|
||||
public getActiveSubscriptions(): ActiveSubscriptions {
|
||||
const map = new Map();
|
||||
for (const pubSubTopic of this.pubSubTopics) {
|
||||
map.set(pubSubTopic, Array.from(this.observers.keys()));
|
||||
for (const pubsubTopic of this.pubsubTopics) {
|
||||
map.set(pubsubTopic, Array.from(this.observers.keys()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@ -191,13 +191,13 @@ class Relay implements IRelay {
|
||||
}
|
||||
|
||||
private subscribeToAllTopics(): void {
|
||||
for (const pubSubTopic of this.pubSubTopics) {
|
||||
this.gossipSubSubscribe(pubSubTopic);
|
||||
for (const pubsubTopic of this.pubsubTopics) {
|
||||
this.gossipSubSubscribe(pubsubTopic);
|
||||
}
|
||||
}
|
||||
|
||||
private async processIncomingMessage<T extends IDecodedMessage>(
|
||||
pubSubTopic: string,
|
||||
pubsubTopic: string,
|
||||
bytes: Uint8Array
|
||||
): Promise<void> {
|
||||
const topicOnlyMsg = await this.defaultDecoder.fromWireToProtoObj(bytes);
|
||||
@ -206,8 +206,8 @@ class Relay implements IRelay {
|
||||
return;
|
||||
}
|
||||
|
||||
// Retrieve the map of content topics for the given pubSubTopic
|
||||
const contentTopicMap = this.observers.get(pubSubTopic);
|
||||
// Retrieve the map of content topics for the given pubsubTopic
|
||||
const contentTopicMap = this.observers.get(pubsubTopic);
|
||||
if (!contentTopicMap) {
|
||||
return;
|
||||
}
|
||||
@ -231,7 +231,7 @@ class Relay implements IRelay {
|
||||
);
|
||||
return;
|
||||
}
|
||||
const msg = await decoder.fromProtoObj(pubSubTopic, protoMsg);
|
||||
const msg = await decoder.fromProtoObj(pubsubTopic, protoMsg);
|
||||
if (msg) {
|
||||
await callback(msg);
|
||||
} else {
|
||||
@ -250,12 +250,12 @@ class Relay implements IRelay {
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
private gossipSubSubscribe(pubSubTopic: string): void {
|
||||
private gossipSubSubscribe(pubsubTopic: string): void {
|
||||
this.gossipSub.addEventListener(
|
||||
"gossipsub:message",
|
||||
(event: CustomEvent<GossipsubMessage>) => {
|
||||
if (event.detail.msg.topic !== pubSubTopic) return;
|
||||
log(`Message received on ${pubSubTopic}`);
|
||||
if (event.detail.msg.topic !== pubsubTopic) return;
|
||||
log(`Message received on ${pubsubTopic}`);
|
||||
|
||||
this.processIncomingMessage(
|
||||
event.detail.msg.topic,
|
||||
@ -264,8 +264,8 @@ class Relay implements IRelay {
|
||||
}
|
||||
);
|
||||
|
||||
this.gossipSub.topicValidators.set(pubSubTopic, messageValidator);
|
||||
this.gossipSub.subscribe(pubSubTopic);
|
||||
this.gossipSub.topicValidators.set(pubsubTopic, messageValidator);
|
||||
this.gossipSub.subscribe(pubsubTopic);
|
||||
}
|
||||
|
||||
private isRelayPubSub(pubsub: PubSub | undefined): boolean {
|
||||
|
@ -14,7 +14,7 @@ describe("Message Validator", () => {
|
||||
fc.uint8Array({ minLength: 1 }),
|
||||
fc.string({ minLength: 1 }),
|
||||
fc.string({ minLength: 1 }),
|
||||
async (payload, pubSubTopic, contentTopic) => {
|
||||
async (payload, pubsubTopic, contentTopic) => {
|
||||
const peerId = await createSecp256k1PeerId();
|
||||
|
||||
const encoder = createEncoder({ contentTopic });
|
||||
@ -22,7 +22,7 @@ describe("Message Validator", () => {
|
||||
|
||||
const message: UnsignedMessage = {
|
||||
type: "unsigned",
|
||||
topic: pubSubTopic,
|
||||
topic: pubsubTopic,
|
||||
data: bytes
|
||||
};
|
||||
|
||||
@ -39,12 +39,12 @@ describe("Message Validator", () => {
|
||||
fc.asyncProperty(
|
||||
fc.uint8Array(),
|
||||
fc.string(),
|
||||
async (data, pubSubTopic) => {
|
||||
async (data, pubsubTopic) => {
|
||||
const peerId = await createSecp256k1PeerId();
|
||||
|
||||
const message: UnsignedMessage = {
|
||||
type: "unsigned",
|
||||
topic: pubSubTopic,
|
||||
topic: pubsubTopic,
|
||||
data
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@ export class TopicOnlyMessage implements IDecodedMessage {
|
||||
public ephemeral: undefined;
|
||||
|
||||
constructor(
|
||||
public pubSubTopic: string,
|
||||
public pubsubTopic: string,
|
||||
private proto: ProtoTopicOnlyMessage
|
||||
) {}
|
||||
|
||||
@ -27,7 +27,7 @@ export class TopicOnlyMessage implements IDecodedMessage {
|
||||
}
|
||||
|
||||
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
||||
pubSubTopic = DefaultPubSubTopic;
|
||||
pubsubTopic = DefaultPubSubTopic;
|
||||
public contentTopic = "";
|
||||
|
||||
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
||||
@ -45,9 +45,9 @@ export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
||||
}
|
||||
|
||||
async fromProtoObj(
|
||||
pubSubTopic: string,
|
||||
pubsubTopic: string,
|
||||
proto: IProtoMessage
|
||||
): Promise<TopicOnlyMessage | undefined> {
|
||||
return new TopicOnlyMessage(pubSubTopic, proto);
|
||||
return new TopicOnlyMessage(pubsubTopic, proto);
|
||||
}
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ export async function createLightNode(
|
||||
): Promise<LightNode> {
|
||||
options = options ?? {};
|
||||
|
||||
if (!options.pubSubTopics) {
|
||||
options.pubSubTopics = [DefaultPubSubTopic];
|
||||
if (!options.pubsubTopics) {
|
||||
options.pubsubTopics = [DefaultPubSubTopic];
|
||||
}
|
||||
|
||||
const libp2pOptions = options?.libp2p ?? {};
|
||||
@ -69,7 +69,7 @@ export async function createLightNode(
|
||||
|
||||
return new WakuNode(
|
||||
options ?? {},
|
||||
options.pubSubTopics,
|
||||
options.pubsubTopics,
|
||||
libp2p,
|
||||
store,
|
||||
lightPush,
|
||||
@ -86,8 +86,8 @@ export async function createRelayNode(
|
||||
): Promise<RelayNode> {
|
||||
options = options ?? {};
|
||||
|
||||
if (!options.pubSubTopics) {
|
||||
options.pubSubTopics = [DefaultPubSubTopic];
|
||||
if (!options.pubsubTopics) {
|
||||
options.pubsubTopics = [DefaultPubSubTopic];
|
||||
}
|
||||
|
||||
const libp2pOptions = options?.libp2p ?? {};
|
||||
@ -107,7 +107,7 @@ export async function createRelayNode(
|
||||
|
||||
return new WakuNode(
|
||||
options,
|
||||
options.pubSubTopics,
|
||||
options.pubsubTopics,
|
||||
libp2p,
|
||||
undefined,
|
||||
undefined,
|
||||
@ -134,8 +134,8 @@ export async function createFullNode(
|
||||
): Promise<FullNode> {
|
||||
options = options ?? {};
|
||||
|
||||
if (!options.pubSubTopics) {
|
||||
options.pubSubTopics = [DefaultPubSubTopic];
|
||||
if (!options.pubsubTopics) {
|
||||
options.pubsubTopics = [DefaultPubSubTopic];
|
||||
}
|
||||
|
||||
const libp2pOptions = options?.libp2p ?? {};
|
||||
@ -158,7 +158,7 @@ export async function createFullNode(
|
||||
|
||||
return new WakuNode(
|
||||
options ?? {},
|
||||
options.pubSubTopics,
|
||||
options.pubsubTopics,
|
||||
libp2p,
|
||||
store,
|
||||
lightPush,
|
||||
|
@ -64,20 +64,20 @@ export class MessageCollector {
|
||||
async waitForMessages(
|
||||
numMessages: number,
|
||||
options?: {
|
||||
pubSubTopic?: string;
|
||||
pubsubTopic?: string;
|
||||
timeoutDuration?: number;
|
||||
exact?: boolean;
|
||||
}
|
||||
): Promise<boolean> {
|
||||
const startTime = Date.now();
|
||||
const pubSubTopic = options?.pubSubTopic || DefaultPubSubTopic;
|
||||
const pubsubTopic = options?.pubsubTopic || DefaultPubSubTopic;
|
||||
const timeoutDuration = options?.timeoutDuration || 400;
|
||||
const exact = options?.exact || false;
|
||||
|
||||
while (this.count < numMessages) {
|
||||
if (this.nwaku) {
|
||||
try {
|
||||
this.list = await this.nwaku.messages(pubSubTopic);
|
||||
this.list = await this.nwaku.messages(pubsubTopic);
|
||||
} catch (error) {
|
||||
log(`Can't retrieve messages because of ${error}`);
|
||||
await delay(10);
|
||||
@ -191,11 +191,11 @@ export class MessageCollector {
|
||||
}
|
||||
} else {
|
||||
// js-waku message specific assertions
|
||||
expect(message.pubSubTopic).to.eq(
|
||||
expect(message.pubsubTopic).to.eq(
|
||||
options.expectedPubSubTopic || DefaultPubSubTopic,
|
||||
`Message pub/sub topic mismatch. Expected: ${
|
||||
options.expectedPubSubTopic || DefaultPubSubTopic
|
||||
}. Got: ${message.pubSubTopic}`
|
||||
}. Got: ${message.pubsubTopic}`
|
||||
);
|
||||
|
||||
expect(bytesToUtf8(message.payload)).to.eq(
|
||||
|
@ -216,7 +216,7 @@ export class NimGoNode {
|
||||
|
||||
async sendMessage(
|
||||
message: MessageRpcQuery,
|
||||
pubSubTopic: string = DefaultPubSubTopic
|
||||
pubsubTopic: string = DefaultPubSubTopic
|
||||
): Promise<boolean> {
|
||||
this.checkProcess();
|
||||
|
||||
@ -225,7 +225,7 @@ export class NimGoNode {
|
||||
}
|
||||
|
||||
return this.rpcCall<boolean>("post_waku_v2_relay_v1_message", [
|
||||
pubSubTopic,
|
||||
pubsubTopic,
|
||||
message
|
||||
]);
|
||||
}
|
||||
@ -264,7 +264,7 @@ export class NimGoNode {
|
||||
async postAsymmetricMessage(
|
||||
message: MessageRpcQuery,
|
||||
publicKey: Uint8Array,
|
||||
pubSubTopic?: string
|
||||
pubsubTopic?: string
|
||||
): Promise<boolean> {
|
||||
this.checkProcess();
|
||||
|
||||
@ -273,7 +273,7 @@ export class NimGoNode {
|
||||
}
|
||||
|
||||
return this.rpcCall<boolean>("post_waku_v2_private_v1_asymmetric_message", [
|
||||
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
|
||||
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
|
||||
message,
|
||||
"0x" + bytesToHex(publicKey)
|
||||
]);
|
||||
@ -281,14 +281,14 @@ export class NimGoNode {
|
||||
|
||||
async getAsymmetricMessages(
|
||||
privateKey: Uint8Array,
|
||||
pubSubTopic?: string
|
||||
pubsubTopic?: string
|
||||
): Promise<MessageRpcResponse[]> {
|
||||
this.checkProcess();
|
||||
|
||||
return await this.rpcCall<MessageRpcResponse[]>(
|
||||
"get_waku_v2_private_v1_asymmetric_messages",
|
||||
[
|
||||
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
|
||||
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
|
||||
"0x" + bytesToHex(privateKey)
|
||||
]
|
||||
);
|
||||
@ -306,7 +306,7 @@ export class NimGoNode {
|
||||
async postSymmetricMessage(
|
||||
message: MessageRpcQuery,
|
||||
symKey: Uint8Array,
|
||||
pubSubTopic?: string
|
||||
pubsubTopic?: string
|
||||
): Promise<boolean> {
|
||||
this.checkProcess();
|
||||
|
||||
@ -315,7 +315,7 @@ export class NimGoNode {
|
||||
}
|
||||
|
||||
return this.rpcCall<boolean>("post_waku_v2_private_v1_symmetric_message", [
|
||||
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
|
||||
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
|
||||
message,
|
||||
"0x" + bytesToHex(symKey)
|
||||
]);
|
||||
@ -323,14 +323,14 @@ export class NimGoNode {
|
||||
|
||||
async getSymmetricMessages(
|
||||
symKey: Uint8Array,
|
||||
pubSubTopic?: string
|
||||
pubsubTopic?: string
|
||||
): Promise<MessageRpcResponse[]> {
|
||||
this.checkProcess();
|
||||
|
||||
return await this.rpcCall<MessageRpcResponse[]>(
|
||||
"get_waku_v2_private_v1_symmetric_messages",
|
||||
[
|
||||
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
|
||||
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
|
||||
"0x" + bytesToHex(symKey)
|
||||
]
|
||||
);
|
||||
|
@ -34,7 +34,7 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
|
||||
const customPubSubTopic = "/waku/2/custom-dapp/proto";
|
||||
const customContentTopic = "/test/2/waku-filter";
|
||||
const newEncoder = createEncoder({
|
||||
pubSubTopic: customPubSubTopic,
|
||||
pubsubTopic: customPubSubTopic,
|
||||
contentTopic: customContentTopic
|
||||
});
|
||||
const newDecoder = createDecoder(customContentTopic, customPubSubTopic);
|
||||
@ -124,10 +124,10 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
|
||||
// While loop is done because of https://github.com/waku-org/js-waku/issues/1606
|
||||
while (
|
||||
!(await messageCollector.waitForMessages(1, {
|
||||
pubSubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubSubTopic
|
||||
})) ||
|
||||
!(await messageCollector2.waitForMessages(1, {
|
||||
pubSubTopic: DefaultPubSubTopic
|
||||
pubsubTopic: DefaultPubSubTopic
|
||||
}))
|
||||
) {
|
||||
await waku.lightPush.send(newEncoder, { payload: utf8ToBytes("M1") });
|
||||
|
@ -65,7 +65,7 @@ export async function validatePingError(
|
||||
|
||||
export async function runNodes(
|
||||
context: Context,
|
||||
pubSubTopics: string[]
|
||||
pubsubTopics: string[]
|
||||
): Promise<[NimGoNode, LightNode]> {
|
||||
const nwaku = new NimGoNode(makeLogFileName(context));
|
||||
|
||||
@ -74,7 +74,7 @@ export async function runNodes(
|
||||
filter: true,
|
||||
lightpush: true,
|
||||
relay: true,
|
||||
topic: pubSubTopics
|
||||
topic: pubsubTopics
|
||||
},
|
||||
{ retries: 3 }
|
||||
);
|
||||
@ -82,7 +82,7 @@ export async function runNodes(
|
||||
let waku: LightNode | undefined;
|
||||
try {
|
||||
waku = await createLightNode({
|
||||
pubSubTopics: pubSubTopics,
|
||||
pubsubTopics: pubsubTopics,
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||
});
|
||||
@ -94,7 +94,7 @@ export async function runNodes(
|
||||
if (waku) {
|
||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
||||
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
|
||||
await nwaku.ensureSubscriptions(pubSubTopics);
|
||||
await nwaku.ensureSubscriptions(pubsubTopics);
|
||||
return [nwaku, waku];
|
||||
} else {
|
||||
throw new Error("Failed to initialize waku");
|
||||
|
@ -32,7 +32,7 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
|
||||
const customContentTopic = "/test/2/waku-light-push/utf8";
|
||||
const customEncoder = createEncoder({
|
||||
contentTopic: customContentTopic,
|
||||
pubSubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubSubTopic
|
||||
});
|
||||
let nimPeerId: PeerId;
|
||||
|
||||
@ -51,7 +51,7 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
|
||||
await tearDownNodes([nwaku, nwaku2], waku);
|
||||
});
|
||||
|
||||
it("Push message on custom pubSubTopic", async function () {
|
||||
it("Push message on custom pubsubTopic", async function () {
|
||||
const pushResponse = await waku.lightPush.send(customEncoder, {
|
||||
payload: utf8ToBytes(messageText)
|
||||
});
|
||||
@ -60,7 +60,7 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
|
||||
|
||||
expect(
|
||||
await messageCollector.waitForMessages(1, {
|
||||
pubSubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubSubTopic
|
||||
})
|
||||
).to.eq(true);
|
||||
messageCollector.verifyReceivedMessage(0, {
|
||||
@ -83,13 +83,13 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
|
||||
|
||||
expect(
|
||||
await messageCollector.waitForMessages(1, {
|
||||
pubSubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubSubTopic
|
||||
})
|
||||
).to.eq(true);
|
||||
|
||||
expect(
|
||||
await messageCollector2.waitForMessages(1, {
|
||||
pubSubTopic: DefaultPubSubTopic
|
||||
pubsubTopic: DefaultPubSubTopic
|
||||
})
|
||||
).to.eq(true);
|
||||
|
||||
@ -126,10 +126,10 @@ describe("Waku Light Push : Multiple PubSubtopics", function () {
|
||||
// While loop is done because of https://github.com/waku-org/js-waku/issues/1606
|
||||
while (
|
||||
!(await messageCollector.waitForMessages(1, {
|
||||
pubSubTopic: customPubSubTopic
|
||||
pubsubTopic: customPubSubTopic
|
||||
})) ||
|
||||
!(await messageCollector2.waitForMessages(1, {
|
||||
pubSubTopic: DefaultPubSubTopic
|
||||
pubsubTopic: DefaultPubSubTopic
|
||||
})) ||
|
||||
pushResponse1!.recipients[0].toString() ===
|
||||
pushResponse2!.recipients[0].toString()
|
||||
|
@ -14,18 +14,18 @@ export const messagePayload = { payload: utf8ToBytes(messageText) };
|
||||
|
||||
export async function runNodes(
|
||||
context: Mocha.Context,
|
||||
pubSubTopics: string[]
|
||||
pubsubTopics: string[]
|
||||
): Promise<[NimGoNode, LightNode]> {
|
||||
const nwaku = new NimGoNode(makeLogFileName(context));
|
||||
await nwaku.start(
|
||||
{ lightpush: true, relay: true, topic: pubSubTopics },
|
||||
{ lightpush: true, relay: true, topic: pubsubTopics },
|
||||
{ retries: 3 }
|
||||
);
|
||||
|
||||
let waku: LightNode | undefined;
|
||||
try {
|
||||
waku = await createLightNode({
|
||||
pubSubTopics: pubSubTopics,
|
||||
pubsubTopics: pubsubTopics,
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
});
|
||||
await waku.start();
|
||||
@ -36,7 +36,7 @@ export async function runNodes(
|
||||
if (waku) {
|
||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
||||
await waitForRemotePeer(waku, [Protocols.LightPush]);
|
||||
await nwaku.ensureSubscriptions(pubSubTopics);
|
||||
await nwaku.ensureSubscriptions(pubsubTopics);
|
||||
return [nwaku, waku];
|
||||
} else {
|
||||
throw new Error("Failed to initialize waku");
|
||||
|
@ -267,7 +267,7 @@ describe("Waku Relay [node only]", () => {
|
||||
|
||||
const CustomEncoder = createEncoder({
|
||||
contentTopic: CustomContentTopic,
|
||||
pubSubTopic: CustomPubSubTopic
|
||||
pubsubTopic: CustomPubSubTopic
|
||||
});
|
||||
const CustomDecoder = createDecoder(CustomContentTopic, CustomPubSubTopic);
|
||||
|
||||
@ -301,16 +301,16 @@ describe("Waku Relay [node only]", () => {
|
||||
|
||||
[waku1, waku2, waku3] = await Promise.all([
|
||||
createRelayNode({
|
||||
pubSubTopics: [testItem.pubsub],
|
||||
pubsubTopics: [testItem.pubsub],
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubSubTopics: [testItem.pubsub],
|
||||
pubsubTopics: [testItem.pubsub],
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubSubTopics: [testItem.pubsub],
|
||||
pubsubTopics: [testItem.pubsub],
|
||||
staticNoiseKey: NOISE_KEY_3
|
||||
}).then((waku) => waku.start().then(() => waku))
|
||||
]);
|
||||
@ -401,16 +401,16 @@ describe("Waku Relay [node only]", () => {
|
||||
// Waku1 and waku2 are using multiple pubsub topis
|
||||
[waku1, waku2, waku3] = await Promise.all([
|
||||
createRelayNode({
|
||||
pubSubTopics: [DefaultPubSubTopic, CustomPubSubTopic],
|
||||
pubsubTopics: [DefaultPubSubTopic, CustomPubSubTopic],
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubSubTopics: [DefaultPubSubTopic, CustomPubSubTopic],
|
||||
pubsubTopics: [DefaultPubSubTopic, CustomPubSubTopic],
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubSubTopics: [DefaultPubSubTopic],
|
||||
pubsubTopics: [DefaultPubSubTopic],
|
||||
staticNoiseKey: NOISE_KEY_3
|
||||
}).then((waku) => waku.start().then(() => waku))
|
||||
]);
|
||||
@ -475,11 +475,11 @@ describe("Waku Relay [node only]", () => {
|
||||
|
||||
[waku1, waku2, waku3] = await Promise.all([
|
||||
createRelayNode({
|
||||
pubSubTopics: [CustomPubSubTopic],
|
||||
pubsubTopics: [CustomPubSubTopic],
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubSubTopics: [CustomPubSubTopic],
|
||||
pubsubTopics: [CustomPubSubTopic],
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
@ -529,7 +529,7 @@ describe("Waku Relay [node only]", () => {
|
||||
await waku3NoMsgPromise;
|
||||
|
||||
expect(bytesToUtf8(waku2ReceivedMsg.payload!)).to.eq(messageText);
|
||||
expect(waku2ReceivedMsg.pubSubTopic).to.eq(CustomPubSubTopic);
|
||||
expect(waku2ReceivedMsg.pubsubTopic).to.eq(CustomPubSubTopic);
|
||||
});
|
||||
|
||||
it("Publishes <= 1 MB and rejects others", async function () {
|
||||
@ -539,11 +539,11 @@ describe("Waku Relay [node only]", () => {
|
||||
// 1 and 2 uses a custom pubsub
|
||||
[waku1, waku2] = await Promise.all([
|
||||
createRelayNode({
|
||||
pubSubTopics: [CustomPubSubTopic],
|
||||
pubsubTopics: [CustomPubSubTopic],
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
}).then((waku) => waku.start().then(() => waku)),
|
||||
createRelayNode({
|
||||
pubSubTopics: [CustomPubSubTopic],
|
||||
pubsubTopics: [CustomPubSubTopic],
|
||||
staticNoiseKey: NOISE_KEY_2,
|
||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||
}).then((waku) => waku.start().then(() => waku))
|
||||
|
@ -38,10 +38,10 @@ describe("Static Sharding: Peer Management", function () {
|
||||
it("all px service nodes subscribed to the shard topic should be dialed", async function () {
|
||||
this.timeout(100_000);
|
||||
|
||||
const pubSubTopics = ["/waku/2/rs/18/2"];
|
||||
const pubsubTopics = ["/waku/2/rs/18/2"];
|
||||
|
||||
await nwaku1.start({
|
||||
topic: pubSubTopics,
|
||||
topic: pubsubTopics,
|
||||
discv5Discovery: true,
|
||||
peerExchange: true,
|
||||
relay: true
|
||||
@ -50,7 +50,7 @@ describe("Static Sharding: Peer Management", function () {
|
||||
const enr1 = (await nwaku1.info()).enrUri;
|
||||
|
||||
await nwaku2.start({
|
||||
topic: pubSubTopics,
|
||||
topic: pubsubTopics,
|
||||
discv5Discovery: true,
|
||||
peerExchange: true,
|
||||
discv5BootstrapNode: enr1,
|
||||
@ -60,7 +60,7 @@ describe("Static Sharding: Peer Management", function () {
|
||||
const enr2 = (await nwaku2.info()).enrUri;
|
||||
|
||||
await nwaku3.start({
|
||||
topic: pubSubTopics,
|
||||
topic: pubsubTopics,
|
||||
discv5Discovery: true,
|
||||
peerExchange: true,
|
||||
discv5BootstrapNode: enr2,
|
||||
@ -69,7 +69,7 @@ describe("Static Sharding: Peer Management", function () {
|
||||
const nwaku3Ma = await nwaku3.getMultiaddrWithId();
|
||||
|
||||
waku = await createLightNode({
|
||||
pubSubTopics,
|
||||
pubsubTopics,
|
||||
libp2p: {
|
||||
peerDiscovery: [
|
||||
bootstrap({ list: [nwaku3Ma.toString()] }),
|
||||
@ -139,7 +139,7 @@ describe("Static Sharding: Peer Management", function () {
|
||||
const nwaku3Ma = await nwaku3.getMultiaddrWithId();
|
||||
|
||||
waku = await createLightNode({
|
||||
pubSubTopics: pubSubTopicsToDial,
|
||||
pubsubTopics: pubSubTopicsToDial,
|
||||
libp2p: {
|
||||
peerDiscovery: [
|
||||
bootstrap({ list: [nwaku3Ma.toString()] }),
|
||||
|
@ -29,17 +29,17 @@ describe("Static Sharding: Running Nodes", () => {
|
||||
it("configure the node with multiple pubsub topics", async function () {
|
||||
this.timeout(15_000);
|
||||
waku = await createLightNode({
|
||||
pubSubTopics: [PubSubTopic1, PubSubTopic2]
|
||||
pubsubTopics: [PubSubTopic1, PubSubTopic2]
|
||||
});
|
||||
|
||||
const encoder1 = createEncoder({
|
||||
contentTopic: ContentTopic,
|
||||
pubSubTopic: PubSubTopic1
|
||||
pubsubTopic: PubSubTopic1
|
||||
});
|
||||
|
||||
const encoder2 = createEncoder({
|
||||
contentTopic: ContentTopic,
|
||||
pubSubTopic: PubSubTopic2
|
||||
pubsubTopic: PubSubTopic2
|
||||
});
|
||||
|
||||
const request1 = await waku.lightPush.send(encoder1, {
|
||||
@ -57,13 +57,13 @@ describe("Static Sharding: Running Nodes", () => {
|
||||
it("using a protocol with unconfigured pubsub topic should fail", async function () {
|
||||
this.timeout(15_000);
|
||||
waku = await createLightNode({
|
||||
pubSubTopics: [PubSubTopic1]
|
||||
pubsubTopics: [PubSubTopic1]
|
||||
});
|
||||
|
||||
// use a pubsub topic that is not configured
|
||||
const encoder = createEncoder({
|
||||
contentTopic: ContentTopic,
|
||||
pubSubTopic: PubSubTopic2
|
||||
pubsubTopic: PubSubTopic2
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -169,7 +169,7 @@ describe("Waku Store, cursor", function () {
|
||||
}
|
||||
});
|
||||
|
||||
it("Passing cursor with wrong pubSubTopic", async function () {
|
||||
it("Passing cursor with wrong pubsubTopic", async function () {
|
||||
await sendMessages(nwaku, totalMsgs, TestContentTopic, DefaultPubSubTopic);
|
||||
waku = await startAndConnectLightNode(nwaku);
|
||||
|
||||
@ -179,7 +179,7 @@ describe("Waku Store, cursor", function () {
|
||||
messages.push(msg as DecodedMessage);
|
||||
}
|
||||
}
|
||||
messages[5].pubSubTopic = customPubSubTopic;
|
||||
messages[5].pubsubTopic = customPubSubTopic;
|
||||
const cursor = await createCursor(messages[5]);
|
||||
|
||||
try {
|
||||
|
@ -113,7 +113,7 @@ describe("Waku Store, custom pubsub topic", function () {
|
||||
|
||||
waku = await createLightNode({
|
||||
staticNoiseKey: NOISE_KEY_1,
|
||||
pubSubTopics: [customPubSubTopic, DefaultPubSubTopic]
|
||||
pubsubTopics: [customPubSubTopic, DefaultPubSubTopic]
|
||||
});
|
||||
await waku.start();
|
||||
|
||||
|
@ -31,7 +31,7 @@ export async function sendMessages(
|
||||
instance: NimGoNode,
|
||||
numMessages: number,
|
||||
contentTopic: string,
|
||||
pubSubTopic: string
|
||||
pubsubTopic: string
|
||||
): Promise<void> {
|
||||
for (let i = 0; i < numMessages; i++) {
|
||||
expect(
|
||||
@ -40,7 +40,7 @@ export async function sendMessages(
|
||||
payload: new Uint8Array([i]),
|
||||
contentTopic: contentTopic
|
||||
}),
|
||||
pubSubTopic
|
||||
pubsubTopic
|
||||
)
|
||||
).to.eq(true);
|
||||
await delay(1); // to ensure each timestamp is unique.
|
||||
@ -56,7 +56,7 @@ export async function processQueriedMessages(
|
||||
for await (const query of instance.store.queryGenerator(decoders)) {
|
||||
for await (const msg of query) {
|
||||
if (msg) {
|
||||
expect(msg.pubSubTopic).to.eq(expectedTopic);
|
||||
expect(msg.pubsubTopic).to.eq(expectedTopic);
|
||||
localMessages.push(msg as DecodedMessage);
|
||||
}
|
||||
}
|
||||
@ -66,10 +66,10 @@ export async function processQueriedMessages(
|
||||
|
||||
export async function startAndConnectLightNode(
|
||||
instance: NimGoNode,
|
||||
pubSubTopics: string[] = [DefaultPubSubTopic]
|
||||
pubsubTopics: string[] = [DefaultPubSubTopic]
|
||||
): Promise<LightNode> {
|
||||
const waku = await createLightNode({
|
||||
pubSubTopics: pubSubTopics,
|
||||
pubsubTopics: pubsubTopics,
|
||||
staticNoiseKey: NOISE_KEY_1
|
||||
});
|
||||
await waku.start();
|
||||
|
@ -70,7 +70,7 @@ describe("Util: toAsyncIterator: Filter", () => {
|
||||
const { value } = await iterator.next();
|
||||
|
||||
expect(value.contentTopic).to.eq(TestContentTopic);
|
||||
expect(value.pubSubTopic).to.eq(DefaultPubSubTopic);
|
||||
expect(value.pubsubTopic).to.eq(DefaultPubSubTopic);
|
||||
expect(bytesToUtf8(value.payload)).to.eq(messageText);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user