mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-14 03:33:11 +00:00
* fix comment of default number of peers * export default number of peers from base protocol sdk * rename to light_push, move class to separate file * move waitForRemotePeer to sdk package * add todo to move waitForGossipSubPeerInMesh into @waku/relay * clean up waitForRemotePeer, split metadata await from event and optimise, decouple from protocol implementations * simplify and rename ILightPush interface * use only connected peers in light push based on connections instead of peer renewal mechanism * improve readability of result processing in light push * fix check & update tests * address tests, add new test cases, fix racing condition in StreamManager * use libp2p.getPeers * feat: confirm metadata and protocols needed in waitForRemotePeer * rely on passed protocols and fallback to mounted * add I prefix to Waku interface * implement waku.connect method * add docs to IWaku interface * remove export and usage of waitForRemotePeer * move wait for remote peer related to Realy out of @waku/sdk * change tests to use new API * fix linting * update size limit * rename .connect to .waitForPeer * export waitForRemotePeer and mark as deprecated * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer (#2163) * feat: add mocha tests to @waku/sdk and cover waitForRemotePeer * add waitForRemote UTs * remove junk * feat: expose peerId and protocols from WakuNode (#2166) * chore: expose peerId and protocols from WakuNode * remove unused method * move to private method * rename to waitForPeers * up test
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import {
|
|
NetworkConfig,
|
|
ProtocolCreateOptions,
|
|
Protocols
|
|
} from "@waku/interfaces";
|
|
import { createRelayNode } from "@waku/relay";
|
|
import { createLightNode, WakuNode } from "@waku/sdk";
|
|
import {
|
|
derivePubsubTopicsFromNetworkConfig,
|
|
Logger,
|
|
pubsubTopicsToShardInfo
|
|
} from "@waku/utils";
|
|
import { Context } from "mocha";
|
|
|
|
import { NOISE_KEY_1 } from "../constants.js";
|
|
import { makeLogFileName } from "../utils/index.js";
|
|
|
|
import { ServiceNode } from "./service_node.js";
|
|
|
|
export const log = new Logger("test:runNodes");
|
|
|
|
type RunNodesOptions = {
|
|
context: Context;
|
|
networkConfig: NetworkConfig;
|
|
protocols: Protocols[];
|
|
createNode: typeof createLightNode | typeof createRelayNode;
|
|
};
|
|
|
|
export async function runNodes<T>(
|
|
options: RunNodesOptions
|
|
): Promise<[ServiceNode, T]> {
|
|
const { context, networkConfig, createNode, protocols } = options;
|
|
|
|
const nwaku = new ServiceNode(makeLogFileName(context));
|
|
const pubsubTopics = derivePubsubTopicsFromNetworkConfig(networkConfig);
|
|
const shardInfo = pubsubTopicsToShardInfo(pubsubTopics);
|
|
|
|
await nwaku.start(
|
|
{
|
|
filter: true,
|
|
lightpush: true,
|
|
relay: true,
|
|
store: true,
|
|
pubsubTopic: pubsubTopics,
|
|
clusterId: shardInfo.clusterId
|
|
},
|
|
{ retries: 3 }
|
|
);
|
|
const waku_options: ProtocolCreateOptions = {
|
|
staticNoiseKey: NOISE_KEY_1,
|
|
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
|
|
networkConfig: shardInfo
|
|
};
|
|
|
|
log.info("Starting js waku node with :", JSON.stringify(waku_options));
|
|
let waku: WakuNode | undefined;
|
|
try {
|
|
waku = (await createNode(waku_options)) as WakuNode;
|
|
await waku.start();
|
|
} catch (error) {
|
|
log.error("jswaku node failed to start:", error);
|
|
}
|
|
|
|
if (waku) {
|
|
await waku.dial(await nwaku.getMultiaddrWithId());
|
|
await waku.waitForPeers(protocols);
|
|
await nwaku.ensureSubscriptions(pubsubTopics);
|
|
return [nwaku, waku as T];
|
|
} else {
|
|
throw new Error("Failed to initialize waku");
|
|
}
|
|
}
|