mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-22 17:18:15 +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 {
|
export class BaseProtocol {
|
||||||
constructor(
|
constructor(
|
||||||
public multicodec: string,
|
public multicodecs: string[],
|
||||||
public peerStore: PeerStore,
|
public peerStore: PeerStore,
|
||||||
protected getConnections: (peerId?: PeerId) => Connection[]
|
protected getConnections: (peerId?: PeerId) => Connection[]
|
||||||
) {}
|
) {}
|
||||||
@ -24,13 +24,13 @@ export class BaseProtocol {
|
|||||||
* peers.
|
* peers.
|
||||||
*/
|
*/
|
||||||
async peers(): Promise<Peer[]> {
|
async peers(): Promise<Peer[]> {
|
||||||
return getPeersForProtocol(this.peerStore, [this.multicodec]);
|
return getPeersForProtocol(this.peerStore, this.multicodecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getPeer(peerId?: PeerId): Promise<Peer> {
|
protected async getPeer(peerId?: PeerId): Promise<Peer> {
|
||||||
const { peer } = await selectPeerForProtocol(
|
const { peer } = await selectPeerForProtocol(
|
||||||
this.peerStore,
|
this.peerStore,
|
||||||
[this.multicodec],
|
this.multicodecs,
|
||||||
peerId
|
peerId
|
||||||
);
|
);
|
||||||
return peer;
|
return peer;
|
||||||
@ -42,6 +42,6 @@ export class BaseProtocol {
|
|||||||
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(this.multicodec);
|
return connection.newStream(this.multicodecs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ export enum Protocols {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface PointToPointProtocol {
|
export interface PointToPointProtocol {
|
||||||
multicodec: string;
|
multicodecs: string[];
|
||||||
peerStore: PeerStore;
|
peerStore: PeerStore;
|
||||||
peers: () => Promise<Peer[]>;
|
peers: () => Promise<Peer[]>;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user