mirror of https://github.com/status-im/js-waku.git
add: support for user agent to identify libp2p
This commit is contained in:
parent
589d2b3d8a
commit
71fe047254
|
@ -19,6 +19,7 @@ import { StoreCodec, WakuStore } from "./waku_store";
|
|||
|
||||
export const DefaultPingKeepAliveValueSecs = 0;
|
||||
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
||||
export const DefaultUserAgent = "waku-js";
|
||||
|
||||
const log = debug("waku:waku");
|
||||
|
||||
|
@ -37,6 +38,11 @@ export interface WakuOptions {
|
|||
* @default {@link DefaultRelayKeepAliveValueSecs}
|
||||
*/
|
||||
relayKeepAlive?: number;
|
||||
/**
|
||||
* Set the user agent string to be used in identification of the node.
|
||||
* @default {@link DefaultUserAgent}
|
||||
*/
|
||||
userAgent?: string;
|
||||
}
|
||||
|
||||
export class WakuNode implements Waku {
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from "@waku/core";
|
||||
import { PeerDiscoveryStaticPeers } from "@waku/core/lib/peer_discovery_static_list";
|
||||
import { getPredefinedBootstrapNodes } from "@waku/core/lib/predefined_bootstrap_nodes";
|
||||
import { DefaultUserAgent } from "@waku/core/lib/waku";
|
||||
import type { WakuFull, WakuLight, WakuPrivacy } from "@waku/interfaces";
|
||||
import type { Libp2p } from "libp2p";
|
||||
import { createLibp2p, Libp2pOptions } from "libp2p";
|
||||
|
@ -71,7 +72,11 @@ export async function createLightNode(
|
|||
Object.assign(libp2pOptions, { peerDiscovery });
|
||||
}
|
||||
|
||||
const libp2p = await defaultLibp2p(undefined, libp2pOptions);
|
||||
const libp2p = await defaultLibp2p(
|
||||
undefined,
|
||||
libp2pOptions,
|
||||
options?.userAgent
|
||||
);
|
||||
|
||||
const wakuStore = new WakuStore(libp2p, options);
|
||||
const wakuLightPush = new WakuLightPush(libp2p, options);
|
||||
|
@ -100,7 +105,11 @@ export async function createPrivacyNode(
|
|||
Object.assign(libp2pOptions, { peerDiscovery });
|
||||
}
|
||||
|
||||
const libp2p = await defaultLibp2p(new WakuRelay(options), libp2pOptions);
|
||||
const libp2p = await defaultLibp2p(
|
||||
new WakuRelay(options),
|
||||
libp2pOptions,
|
||||
options?.userAgent
|
||||
);
|
||||
|
||||
return new WakuNode(options ?? {}, libp2p) as WakuPrivacy;
|
||||
}
|
||||
|
@ -128,7 +137,11 @@ export async function createFullNode(
|
|||
Object.assign(libp2pOptions, { peerDiscovery });
|
||||
}
|
||||
|
||||
const libp2p = await defaultLibp2p(new WakuRelay(options), libp2pOptions);
|
||||
const libp2p = await defaultLibp2p(
|
||||
new WakuRelay(options),
|
||||
libp2pOptions,
|
||||
options?.userAgent
|
||||
);
|
||||
|
||||
const wakuStore = new WakuStore(libp2p, options);
|
||||
const wakuLightPush = new WakuLightPush(libp2p, options);
|
||||
|
@ -149,14 +162,18 @@ export function defaultPeerDiscovery(): PeerDiscovery {
|
|||
|
||||
export async function defaultLibp2p(
|
||||
wakuRelay?: WakuRelay,
|
||||
options?: Partial<Libp2pOptions>
|
||||
options?: Partial<Libp2pOptions>,
|
||||
userAgent?: string
|
||||
): Promise<Libp2p> {
|
||||
const libp2pOpts = Object.assign(
|
||||
{
|
||||
transports: [new WebSockets({ filter: filterAll })],
|
||||
streamMuxers: [new Mplex()],
|
||||
connectionEncryption: [new Noise()],
|
||||
identify: {
|
||||
host: userAgent || DefaultUserAgent,
|
||||
},
|
||||
} as Libp2pOptions,
|
||||
wakuRelay ? { pubsub: wakuRelay } : {},
|
||||
options ?? {}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue