metadata: store peerIdStr instead of peerId

This commit is contained in:
danisharora099 2024-01-16 13:14:28 +05:30
parent 62725c18ec
commit 7475a2cd3c
No known key found for this signature in database
GPG Key ID: FBD2BF500037F135

View File

@ -3,6 +3,7 @@ import { IncomingStreamData } from "@libp2p/interface/stream-handler";
import type {
IMetadata,
Libp2pComponents,
PeerIdStr,
ShardInfo,
ShardingParams
} from "@waku/interfaces";
@ -21,12 +22,7 @@ export const MetadataCodec = "/vac/waku/metadata/1.0.0";
class Metadata extends BaseProtocol implements IMetadata {
private libp2pComponents: Libp2pComponents;
handshakesConfirmed: Set<PeerId> = new Set();
checkHandshake(peerId: PeerId): boolean {
const handshakesArr = [...this.handshakesConfirmed];
return handshakesArr.some((id) => id.equals(peerId));
}
handshakesConfirmed: Set<PeerIdStr> = new Set();
constructor(
public shardInfo: ShardingParams,
@ -98,7 +94,7 @@ class Metadata extends BaseProtocol implements IMetadata {
}
public async confirmOrAttemptHandshake(peerId: PeerId): Promise<void> {
if (this.checkHandshake(peerId)) return;
if (this.handshakesConfirmed.has(peerId.toString())) return;
await this.query(peerId);
@ -131,7 +127,7 @@ class Metadata extends BaseProtocol implements IMetadata {
}
});
this.handshakesConfirmed.add(peerId);
this.handshakesConfirmed.add(peerId.toString());
}
}