mirror of https://github.com/waku-org/js-waku.git
fix: only override ping metadata in peer store (#1984)
Co-authored-by: Sasha <118575614+weboko@users.noreply.github.com>
This commit is contained in:
parent
1a6bc4f8ce
commit
fb34b7262a
|
@ -56,7 +56,7 @@ export class KeepAliveManager {
|
|||
}
|
||||
|
||||
try {
|
||||
await peerStore.patch(peerId, {
|
||||
await peerStore.merge(peerId, {
|
||||
metadata: {
|
||||
ping: utf8ToBytes(ping.toString())
|
||||
}
|
||||
|
|
|
@ -233,4 +233,35 @@ describe("Metadata Protocol", function () {
|
|||
expect(metadataShardInfo!.clusterId).to.eq(shardInfo.clusterId);
|
||||
expect(metadataShardInfo.shards).to.include.members(shardInfo.shards);
|
||||
});
|
||||
|
||||
it("receiving a ping from a peer does not overwrite shard info", async function () {
|
||||
const shardInfo: ShardInfo = {
|
||||
clusterId: 2,
|
||||
shards: [1]
|
||||
};
|
||||
|
||||
await nwaku1.start({
|
||||
relay: true,
|
||||
discv5Discovery: true,
|
||||
peerExchange: true,
|
||||
clusterId: shardInfo.clusterId,
|
||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
|
||||
});
|
||||
|
||||
const nwaku1Ma = await nwaku1.getMultiaddrWithId();
|
||||
const nwaku1PeerId = await nwaku1.getPeerId();
|
||||
|
||||
waku = await createLightNode({ shardInfo, pingKeepAlive: 1 });
|
||||
await waku.start();
|
||||
await waku.libp2p.dialProtocol(nwaku1Ma, MetadataCodec);
|
||||
|
||||
// delay to ensure the connection is estabilished, shardInfo is updated, and there is a ping
|
||||
await delay(1500);
|
||||
|
||||
const metadata = (await waku.libp2p.peerStore.get(nwaku1PeerId)).metadata;
|
||||
expect(metadata.get("shardInfo")).to.not.be.undefined;
|
||||
|
||||
const pingInfo = metadata.get("ping");
|
||||
expect(pingInfo).to.not.be.undefined;
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue