Use PeerId.toString() instead of toB58String()

New version of `PeerId` will only support `toString`
This commit is contained in:
Franck Royer 2022-06-14 16:12:37 +10:00
parent 3217b28063
commit 6c30e8d400
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
12 changed files with 40 additions and 48 deletions

View File

@ -26,7 +26,7 @@ function info(waku: Waku | undefined): string[] {
if (!waku) { if (!waku) {
return ["Waku node is starting"]; return ["Waku node is starting"];
} }
return [`PeerId: ${waku.libp2p.peerId.toB58String()}`]; return [`PeerId: ${waku.libp2p.peerId.toString()}`];
} }
function connect(peer: string | undefined, waku: Waku | undefined): string[] { function connect(peer: string | undefined, waku: Waku | undefined): string[] {
@ -64,7 +64,7 @@ async function peers(waku: Waku | undefined): Promise<string[]> {
peers.push(peer); peers.push(peer);
} }
Array.from(peers).forEach((peer) => { Array.from(peers).forEach((peer) => {
response.push(peer.id.toB58String() + ":"); response.push(peer.id.toString() + ":");
let addresses = " addresses: ["; let addresses = " addresses: [";
peer.addresses.forEach(({ multiaddr }) => { peer.addresses.forEach(({ multiaddr }) => {
addresses += " " + multiaddr.toString() + ","; addresses += " " + multiaddr.toString() + ",";

View File

@ -171,7 +171,7 @@ describe("DNS Node Discovery w/ capabilities", () => {
}); });
expect(peers.length).to.eq(1); expect(peers.length).to.eq(1);
expect(peers[0].peerId?.toB58String()).to.eq( expect(peers[0].peerId?.toString()).to.eq(
"16Uiu2HAmPsYLvfKafxgRsb6tioYyGnSvGXS2iuMigptHrqHPNPzx" "16Uiu2HAmPsYLvfKafxgRsb6tioYyGnSvGXS2iuMigptHrqHPNPzx"
); );
}); });
@ -186,7 +186,7 @@ describe("DNS Node Discovery w/ capabilities", () => {
}); });
expect(peers.length).to.eq(1); expect(peers.length).to.eq(1);
expect(peers[0].peerId?.toB58String()).to.eq( expect(peers[0].peerId?.toString()).to.eq(
"16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F" "16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F"
); );
}); });
@ -200,7 +200,7 @@ describe("DNS Node Discovery w/ capabilities", () => {
}); });
expect(peers.length).to.eq(1); expect(peers.length).to.eq(1);
expect(peers[0].peerId?.toB58String()).to.eq( expect(peers[0].peerId?.toString()).to.eq(
"16Uiu2HAkv3La3ECgQpdYeEJfrX36EWdhkUDv4C9wvXM8TFZ9dNgd" "16Uiu2HAkv3La3ECgQpdYeEJfrX36EWdhkUDv4C9wvXM8TFZ9dNgd"
); );
}); });
@ -220,7 +220,7 @@ describe("DNS Node Discovery w/ capabilities", () => {
}); });
expect(peers.length).to.eq(2); expect(peers.length).to.eq(2);
const peerIds = peers.map((p) => p.peerId?.toB58String()); const peerIds = peers.map((p) => p.peerId?.toString());
expect(peerIds).to.contain( expect(peerIds).to.contain(
"16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F" "16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F"
); );
@ -246,7 +246,7 @@ describe("DNS Node Discovery w/ capabilities", () => {
}); });
expect(peers.length).to.eq(3); expect(peers.length).to.eq(3);
const peerIds = peers.map((p) => p.peerId?.toB58String()); const peerIds = peers.map((p) => p.peerId?.toString());
expect(peerIds).to.contain( expect(peerIds).to.contain(
"16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F" "16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F"
); );

View File

@ -42,7 +42,7 @@ describe("Fetch nodes until capabilities are fulfilled", function () {
); );
expect(res.length).to.eq(1); expect(res.length).to.eq(1);
expect(res[0].peerId!.toB58String()).to.eq(relayNode.peerId?.toB58String()); expect(res[0].peerId!.toString()).to.eq(relayNode.peerId?.toString());
}); });
it("1 Store, 2 fetches", async function () { it("1 Store, 2 fetches", async function () {
@ -65,7 +65,7 @@ describe("Fetch nodes until capabilities are fulfilled", function () {
); );
expect(res.length).to.eq(1); expect(res.length).to.eq(1);
expect(res[0].peerId!.toB58String()).to.eq(storeNode.peerId?.toB58String()); expect(res[0].peerId!.toString()).to.eq(storeNode.peerId?.toString());
}); });
it("1 Store, 2 relays, 2 fetches", async function () { it("1 Store, 2 relays, 2 fetches", async function () {
@ -94,15 +94,9 @@ describe("Fetch nodes until capabilities are fulfilled", function () {
); );
expect(res.length).to.eq(3); expect(res.length).to.eq(3);
expect(res[0].peerId!.toB58String()).to.eq( expect(res[0].peerId!.toString()).to.eq(relayNode1.peerId?.toString());
relayNode1.peerId?.toB58String() expect(res[1].peerId!.toString()).to.eq(relayNode2.peerId?.toString());
); expect(res[2].peerId!.toString()).to.eq(relayStoreNode.peerId?.toString());
expect(res[1].peerId!.toB58String()).to.eq(
relayNode2.peerId?.toB58String()
);
expect(res[2].peerId!.toB58String()).to.eq(
relayStoreNode.peerId?.toB58String()
);
}); });
it("1 Relay, 1 Filter, gives up", async function () { it("1 Relay, 1 Filter, gives up", async function () {
@ -117,6 +111,6 @@ describe("Fetch nodes until capabilities are fulfilled", function () {
); );
expect(res.length).to.eq(1); expect(res.length).to.eq(1);
expect(res[0].peerId!.toB58String()).to.eq(relayNode.peerId?.toB58String()); expect(res[0].peerId!.toString()).to.eq(relayNode.peerId?.toString());
}); });
}); });

View File

@ -36,7 +36,7 @@ describe("ENR Interop: nwaku", function () {
expect(nwakuInfo.enrUri).to.not.be.undefined; expect(nwakuInfo.enrUri).to.not.be.undefined;
const dec = await ENR.decodeTxt(nwakuInfo.enrUri ?? ""); const dec = await ENR.decodeTxt(nwakuInfo.enrUri ?? "");
expect(dec.peerId?.toB58String()).to.eq(nimPeerId.toB58String()); expect(dec.peerId?.toString()).to.eq(nimPeerId.toString());
expect(dec.waku2).to.deep.eq({ expect(dec.waku2).to.deep.eq({
relay: true, relay: true,
store: false, store: false,
@ -67,7 +67,7 @@ describe("ENR Interop: nwaku", function () {
expect(nwakuInfo.enrUri).to.not.be.undefined; expect(nwakuInfo.enrUri).to.not.be.undefined;
const dec = await ENR.decodeTxt(nwakuInfo.enrUri ?? ""); const dec = await ENR.decodeTxt(nwakuInfo.enrUri ?? "");
expect(dec.peerId?.toB58String()).to.eq(nimPeerId.toB58String()); expect(dec.peerId?.toString()).to.eq(nimPeerId.toString());
expect(dec.waku2).to.deep.eq({ expect(dec.waku2).to.deep.eq({
relay: true, relay: true,
store: true, store: true,
@ -98,7 +98,7 @@ describe("ENR Interop: nwaku", function () {
expect(nwakuInfo.enrUri).to.not.be.undefined; expect(nwakuInfo.enrUri).to.not.be.undefined;
const dec = await ENR.decodeTxt(nwakuInfo.enrUri ?? ""); const dec = await ENR.decodeTxt(nwakuInfo.enrUri ?? "");
expect(dec.peerId?.toB58String()).to.eq(nimPeerId.toB58String()); expect(dec.peerId?.toString()).to.eq(nimPeerId.toString());
expect(dec.waku2).to.deep.eq({ expect(dec.waku2).to.deep.eq({
relay: true, relay: true,
store: true, store: true,

View File

@ -102,7 +102,7 @@ describe("ENR", function () {
expect(enr.ip).to.not.be.undefined; expect(enr.ip).to.not.be.undefined;
expect(enr.ip).to.be.equal("134.209.139.210"); expect(enr.ip).to.be.equal("134.209.139.210");
expect(enr.publicKey).to.not.be.undefined; expect(enr.publicKey).to.not.be.undefined;
expect(enr.peerId?.toB58String()).to.be.equal( expect(enr.peerId?.toString()).to.be.equal(
"16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ" "16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ"
); );
}); });

View File

@ -422,9 +422,7 @@ export class ENR extends Map<ENRKey, ENRValue> {
if (this.peerId) { if (this.peerId) {
const locationMultiaddr = this.getLocationMultiaddr(protocol); const locationMultiaddr = this.getLocationMultiaddr(protocol);
if (locationMultiaddr) { if (locationMultiaddr) {
return locationMultiaddr.encapsulate( return locationMultiaddr.encapsulate(`/p2p/${this.peerId.toString()}`);
`/p2p/${this.peerId.toB58String()}`
);
} }
} }
return; return;
@ -437,7 +435,7 @@ export class ENR extends Map<ENRKey, ENRValue> {
if (this.peerId && this.multiaddrs) { if (this.peerId && this.multiaddrs) {
const peerId = this.peerId; const peerId = this.peerId;
return this.multiaddrs.map((ma) => { return this.multiaddrs.map((ma) => {
return ma.encapsulate(`/p2p/${peerId.toB58String()}`); return ma.encapsulate(`/p2p/${peerId.toString()}`);
}); });
} }
return []; return [];

View File

@ -69,7 +69,7 @@ describe("Waku Dial [node only]", function () {
}); });
}); });
expect(connectedPeerID.toB58String()).to.eq(multiAddrWithId.getPeerId()); expect(connectedPeerID.toString()).to.eq(multiAddrWithId.getPeerId());
}); });
it("Passing a function", async function () { it("Passing a function", async function () {
@ -94,7 +94,7 @@ describe("Waku Dial [node only]", function () {
}); });
const multiAddrWithId = await nwaku.getMultiaddrWithId(); const multiAddrWithId = await nwaku.getMultiaddrWithId();
expect(connectedPeerID.toB58String()).to.eq(multiAddrWithId.getPeerId()); expect(connectedPeerID.toString()).to.eq(multiAddrWithId.getPeerId());
}); });
}); });
}); });
@ -249,7 +249,7 @@ describe("Wait for remote peer / get peers", function () {
const peers = []; const peers = [];
for await (const peer of waku.store.peers) { for await (const peer of waku.store.peers) {
peers.push(peer.id.toB58String()); peers.push(peer.id.toString());
} }
const nimPeerId = multiAddrWithId.getPeerId(); const nimPeerId = multiAddrWithId.getPeerId();
@ -274,7 +274,7 @@ describe("Wait for remote peer / get peers", function () {
const peers = []; const peers = [];
for await (const peer of waku.store.peers) { for await (const peer of waku.store.peers) {
peers.push(peer.id.toB58String()); peers.push(peer.id.toString());
} }
const nimPeerId = multiAddrWithId.getPeerId(); const nimPeerId = multiAddrWithId.getPeerId();
@ -297,7 +297,7 @@ describe("Wait for remote peer / get peers", function () {
const peers = []; const peers = [];
for await (const peer of waku.lightPush.peers) { for await (const peer of waku.lightPush.peers) {
peers.push(peer.id.toB58String()); peers.push(peer.id.toString());
} }
const nimPeerId = multiAddrWithId.getPeerId(); const nimPeerId = multiAddrWithId.getPeerId();
@ -320,7 +320,7 @@ describe("Wait for remote peer / get peers", function () {
const peers = []; const peers = [];
for await (const peer of waku.filter.peers) { for await (const peer of waku.filter.peers) {
peers.push(peer.id.toB58String()); peers.push(peer.id.toString());
} }
const nimPeerId = multiAddrWithId.getPeerId(); const nimPeerId = multiAddrWithId.getPeerId();

View File

@ -346,7 +346,7 @@ export class Waku {
if (!localMultiaddr || localMultiaddr.toString() === "") { if (!localMultiaddr || localMultiaddr.toString() === "") {
throw "Not listening on localhost"; throw "Not listening on localhost";
} }
return localMultiaddr + "/p2p/" + this.libp2p.peerId.toB58String(); return localMultiaddr + "/p2p/" + this.libp2p.peerId.toString();
} }
/** /**
@ -388,7 +388,7 @@ export class Waku {
if (protocols.includes(Protocols.Store)) { if (protocols.includes(Protocols.Store)) {
const storePromise = (async (): Promise<void> => { const storePromise = (async (): Promise<void> => {
for await (const peer of this.store.peers) { for await (const peer of this.store.peers) {
dbg("Store peer found", peer.id.toB58String()); dbg("Store peer found", peer.id.toString());
break; break;
} }
})(); })();
@ -398,7 +398,7 @@ export class Waku {
if (protocols.includes(Protocols.LightPush)) { if (protocols.includes(Protocols.LightPush)) {
const lightPushPromise = (async (): Promise<void> => { const lightPushPromise = (async (): Promise<void> => {
for await (const peer of this.lightPush.peers) { for await (const peer of this.lightPush.peers) {
dbg("Light Push peer found", peer.id.toB58String()); dbg("Light Push peer found", peer.id.toString());
break; break;
} }
})(); })();
@ -408,7 +408,7 @@ export class Waku {
if (protocols.includes(Protocols.Filter)) { if (protocols.includes(Protocols.Filter)) {
const filterPromise = (async (): Promise<void> => { const filterPromise = (async (): Promise<void> => {
for await (const peer of this.filter.peers) { for await (const peer of this.filter.peers) {
dbg("Filter peer found", peer.id.toB58String()); dbg("Filter peer found", peer.id.toString());
break; break;
} }
})(); })();
@ -434,7 +434,7 @@ export class Waku {
// Just in case a timer already exist for this peer // Just in case a timer already exist for this peer
this.stopKeepAlive(peerId); this.stopKeepAlive(peerId);
const peerIdStr = peerId.toB58String(); const peerIdStr = peerId.toString();
if (pingPeriodSecs !== 0) { if (pingPeriodSecs !== 0) {
const pingService = new PingService(this.libp2p); const pingService = new PingService(this.libp2p);
@ -455,7 +455,7 @@ export class Waku {
} }
private stopKeepAlive(peerId: PeerId): void { private stopKeepAlive(peerId: PeerId): void {
const peerIdStr = peerId.toB58String(); const peerIdStr = peerId.toString();
if (this.pingKeepAliveTimers[peerIdStr]) { if (this.pingKeepAliveTimers[peerIdStr]) {
clearInterval(this.pingKeepAliveTimers[peerIdStr]); clearInterval(this.pingKeepAliveTimers[peerIdStr]);

View File

@ -87,7 +87,7 @@ export class WakuFilter {
} catch (e) { } catch (e) {
log( log(
"Error subscribing to peer ", "Error subscribing to peer ",
peer.id.toB58String(), peer.id.toString(),
"for content topics", "for content topics",
contentTopics, contentTopics,
": ", ": ",
@ -200,7 +200,7 @@ export class WakuFilter {
peer = await this.libp2p.peerStore.get(peerId); peer = await this.libp2p.peerStore.get(peerId);
if (!peer) { if (!peer) {
throw new Error( throw new Error(
`Failed to retrieve connection details for provided peer in peer store: ${peerId.toB58String()}` `Failed to retrieve connection details for provided peer in peer store: ${peerId.toString()}`
); );
} }
} else { } else {

View File

@ -70,8 +70,8 @@ describe("Waku Relay [node only]", () => {
waku2.libp2p.pubsub.getSubscribers(DefaultPubSubTopic); waku2.libp2p.pubsub.getSubscribers(DefaultPubSubTopic);
log("Asserting mutual subscription"); log("Asserting mutual subscription");
expect(subscribers1).to.contain(waku2.libp2p.peerId.toB58String()); expect(subscribers1).to.contain(waku2.libp2p.peerId.toString());
expect(subscribers2).to.contain(waku1.libp2p.peerId.toB58String()); expect(subscribers2).to.contain(waku1.libp2p.peerId.toString());
}); });
it("Register correct protocols", async function () { it("Register correct protocols", async function () {
@ -338,7 +338,7 @@ describe("Waku Relay [node only]", () => {
} }
const nimPeerId = await nwaku.getPeerId(); const nimPeerId = await nwaku.getPeerId();
expect(subscribers).to.contain(nimPeerId.toB58String()); expect(subscribers).to.contain(nimPeerId.toString());
}); });
it("Publishes to nwaku", async function () { it("Publishes to nwaku", async function () {

View File

@ -326,7 +326,7 @@ export class WakuRelay extends Gossipsub {
*/ */
async _publish(msg: InMessage): Promise<void> { async _publish(msg: InMessage): Promise<void> {
const msgIdStr = await this.getCanonicalMsgIdStr(msg); const msgIdStr = await this.getCanonicalMsgIdStr(msg);
if (msg.receivedFrom !== this.peerId.toB58String()) { if (msg.receivedFrom !== this.peerId.toString()) {
this.score.deliverMessage(msg, msgIdStr); this.score.deliverMessage(msg, msgIdStr);
this.gossipTracer.deliverMessage(msgIdStr); this.gossipTracer.deliverMessage(msgIdStr);
} }

View File

@ -146,7 +146,7 @@ export class WakuStore {
); );
dbg("Querying history with the following options", { dbg("Querying history with the following options", {
peerId: options?.peerId?.toB58String(), peerId: options?.peerId?.toString(),
...options, ...options,
}); });
@ -154,7 +154,7 @@ export class WakuStore {
if (opts.peerId) { if (opts.peerId) {
peer = await this.libp2p.peerStore.get(opts.peerId); peer = await this.libp2p.peerStore.get(opts.peerId);
if (!peer) if (!peer)
throw `Failed to retrieve connection details for provided peer in peer store: ${opts.peerId.toB58String()}`; throw `Failed to retrieve connection details for provided peer in peer store: ${opts.peerId.toString()}`;
} else { } else {
peer = await this.randomPeer; peer = await this.randomPeer;
if (!peer) if (!peer)
@ -170,7 +170,7 @@ export class WakuStore {
} }
dbg(`Use store codec ${storeCodec}`); dbg(`Use store codec ${storeCodec}`);
if (!storeCodec) if (!storeCodec)
throw `Peer does not register waku store protocol: ${peer.id.toB58String()}`; throw `Peer does not register waku store protocol: ${peer.id.toString()}`;
Object.assign(opts, { storeCodec }); Object.assign(opts, { storeCodec });
const connection = this.libp2p.connectionManager.get(peer.id); const connection = this.libp2p.connectionManager.get(peer.id);