mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-21 08:38:17 +00:00
refactor BaseProtocol
refactor `multicodec` from type `string` to `string[]` as the Filter protocol would now have 2 protocol identifiers
This commit is contained in:
parent
92ccd7ec2f
commit
b30affdb0b
@ -13,7 +13,7 @@ import {
|
||||
*/
|
||||
export class BaseProtocol {
|
||||
constructor(
|
||||
public multicodec: string,
|
||||
public multicodecs: string[],
|
||||
public peerStore: PeerStore,
|
||||
protected getConnections: (peerId?: PeerId) => Connection[]
|
||||
) {}
|
||||
@ -24,13 +24,13 @@ export class BaseProtocol {
|
||||
* peers.
|
||||
*/
|
||||
async peers(): Promise<Peer[]> {
|
||||
return getPeersForProtocol(this.peerStore, [this.multicodec]);
|
||||
return getPeersForProtocol(this.peerStore, this.multicodecs);
|
||||
}
|
||||
|
||||
protected async getPeer(peerId?: PeerId): Promise<Peer> {
|
||||
const { peer } = await selectPeerForProtocol(
|
||||
this.peerStore,
|
||||
[this.multicodec],
|
||||
this.multicodecs,
|
||||
peerId
|
||||
);
|
||||
return peer;
|
||||
@ -42,6 +42,6 @@ export class BaseProtocol {
|
||||
throw new Error("Failed to get a connection to the peer");
|
||||
}
|
||||
|
||||
return connection.newStream(this.multicodec);
|
||||
return connection.newStream(this.multicodecs);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ export enum Protocols {
|
||||
}
|
||||
|
||||
export interface PointToPointProtocol {
|
||||
multicodec: string;
|
||||
multicodecs: string[];
|
||||
peerStore: PeerStore;
|
||||
peers: () => Promise<Peer[]>;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user