chore: use `this.multicodec` over constant

To enable extraction of common functions.
This commit is contained in:
fryorcraken.eth 2023-01-25 17:25:46 +11:00
parent 6b87ca1c4d
commit c85b113df7
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 9 additions and 9 deletions

View File

@ -61,7 +61,7 @@ class Filter implements IFilter {
this.subscriptions = new Map(); this.subscriptions = new Map();
this.decoders = new Map(); this.decoders = new Map();
this.libp2p this.libp2p
.handle(FilterCodec, this.onRequest.bind(this)) .handle(this.multicodec, this.onRequest.bind(this))
.catch((e) => log("Failed to register filter protocol", e)); .catch((e) => log("Failed to register filter protocol", e));
} }
@ -264,23 +264,23 @@ class Filter implements IFilter {
throw new Error("Failed to get a connection to the peer"); throw new Error("Failed to get a connection to the peer");
} }
return connection.newStream(FilterCodec); return connection.newStream(this.multicodec);
} }
private async getPeer(peerId?: PeerId): Promise<Peer> { private async getPeer(peerId?: PeerId): Promise<Peer> {
const res = await selectPeerForProtocol( const res = await selectPeerForProtocol(
this.peerStore, this.peerStore,
[FilterCodec], [this.multicodec],
peerId peerId
); );
if (!res) { if (!res) {
throw new Error(`Failed to select peer for ${FilterCodec}`); throw new Error(`Failed to select peer for ${this.multicodec}`);
} }
return res.peer; return res.peer;
} }
async peers(): Promise<Peer[]> { async peers(): Promise<Peer[]> {
return getPeersForProtocol(this.peerStore, [FilterCodec]); return getPeersForProtocol(this.peerStore, [this.multicodec]);
} }
async randomPeer(): Promise<Peer | undefined> { async randomPeer(): Promise<Peer | undefined> {

View File

@ -67,7 +67,7 @@ class LightPush implements ILightPush {
if (!connection) throw "Failed to get a connection to the peer"; if (!connection) throw "Failed to get a connection to the peer";
const stream = await connection.newStream(LightPushCodec); const stream = await connection.newStream(this.multicodec);
const recipients: PeerId[] = []; const recipients: PeerId[] = [];
@ -116,7 +116,7 @@ class LightPush implements ILightPush {
* peers. * peers.
*/ */
async peers(): Promise<Peer[]> { async peers(): Promise<Peer[]> {
return getPeersForProtocol(this.peerStore, [LightPushCodec]); return getPeersForProtocol(this.peerStore, [this.multicodec]);
} }
/** /**

View File

@ -239,7 +239,7 @@ class Store implements IStore {
const res = await selectPeerForProtocol( const res = await selectPeerForProtocol(
this.peerStore, this.peerStore,
[StoreCodec], [this.multicodec],
options?.peerId options?.peerId
); );
@ -269,7 +269,7 @@ class Store implements IStore {
* store protocol. Waku may or may not be currently connected to these peers. * store protocol. Waku may or may not be currently connected to these peers.
*/ */
async peers(): Promise<Peer[]> { async peers(): Promise<Peer[]> {
return getPeersForProtocol(this.peerStore, [StoreCodec]); return getPeersForProtocol(this.peerStore, [this.multicodec]);
} }
get peerStore(): PeerStore { get peerStore(): PeerStore {