mirror of https://github.com/waku-org/js-waku.git
test: replace nwaku ip with local ip
This commit is contained in:
parent
c8fa8ea20e
commit
afa7262604
|
@ -99,6 +99,7 @@ export class Nwaku {
|
||||||
private pid?: number;
|
private pid?: number;
|
||||||
private peerId?: PeerId;
|
private peerId?: PeerId;
|
||||||
private multiaddrWithId?: Multiaddr;
|
private multiaddrWithId?: Multiaddr;
|
||||||
|
private websocketPort?: number;
|
||||||
private readonly logPath: string;
|
private readonly logPath: string;
|
||||||
private rpcPort?: number;
|
private rpcPort?: number;
|
||||||
|
|
||||||
|
@ -171,6 +172,8 @@ export class Nwaku {
|
||||||
args
|
args
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.websocketPort = mergedArgs.websocketPort;
|
||||||
|
|
||||||
process.env.WAKUNODE2_STORE_MESSAGE_DB_URL = "";
|
process.env.WAKUNODE2_STORE_MESSAGE_DB_URL = "";
|
||||||
|
|
||||||
const argsArray = argsToArray(mergedArgs);
|
const argsArray = argsToArray(mergedArgs);
|
||||||
|
@ -373,29 +376,40 @@ export class Nwaku {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPeerId(): Promise<PeerId> {
|
async getPeerId(): Promise<PeerId> {
|
||||||
return await this._getPeerId().then((res) => res.peerId);
|
if (this.peerId) return this.peerId;
|
||||||
|
this.peerId = await this._getPeerId();
|
||||||
|
return this.peerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMultiaddrWithId(): Promise<Multiaddr> {
|
async getMultiaddrWithId(): Promise<Multiaddr> {
|
||||||
return await this._getPeerId().then((res) => res.multiaddrWithId);
|
if (this.multiaddrWithId) return this.multiaddrWithId;
|
||||||
|
|
||||||
|
if (!this.websocketPort) {
|
||||||
|
return Promise.reject("No websocket port defined.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const peerId = await this.getPeerId();
|
||||||
|
|
||||||
|
this.multiaddrWithId = multiaddr(
|
||||||
|
`/ip4/127.0.0.1/tcp/${this.websocketPort}/ws/p2p/${peerId.toString()}`
|
||||||
|
);
|
||||||
|
return this.multiaddrWithId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getPeerId(): Promise<{
|
private async _getPeerId(): Promise<PeerId> {
|
||||||
peerId: PeerId;
|
if (this.peerId) {
|
||||||
multiaddrWithId: Multiaddr;
|
return this.peerId;
|
||||||
}> {
|
|
||||||
if (this.peerId && this.multiaddrWithId) {
|
|
||||||
return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId };
|
|
||||||
}
|
}
|
||||||
const res = await this.info();
|
const res = await this.info();
|
||||||
this.multiaddrWithId = res.listenAddresses
|
const multiaddrWithId = res.listenAddresses
|
||||||
.map((ma) => multiaddr(ma))
|
.map((ma) => multiaddr(ma))
|
||||||
.find((ma) => ma.protoNames().includes("ws"));
|
.find((ma) => ma.protoNames().includes("ws"));
|
||||||
if (!this.multiaddrWithId) throw "Nwaku did not return a ws multiaddr";
|
if (!multiaddrWithId) throw "Nwaku did not return a ws multiaddr";
|
||||||
const peerIdStr = this.multiaddrWithId.getPeerId();
|
const peerIdStr = multiaddrWithId.getPeerId();
|
||||||
if (!peerIdStr) throw "Nwaku multiaddr does not contain peerId";
|
if (!peerIdStr) throw "Nwaku multiaddr does not contain peerId";
|
||||||
this.peerId = peerIdFromString(peerIdStr);
|
this.peerId = peerIdFromString(peerIdStr);
|
||||||
return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId };
|
|
||||||
|
return this.peerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
get rpcUrl(): string {
|
get rpcUrl(): string {
|
||||||
|
|
Loading…
Reference in New Issue