refactor BaseProtocol

refactor `multicodec` from type `string` to
`string[]` as the Filter protocol would now
have 2 protocol identifiers
This commit is contained in:
danisharora099 2023-04-04 22:21:06 +05:30
parent 92ccd7ec2f
commit b30affdb0b
No known key found for this signature in database
GPG Key ID: FBD2BF500037F135
2 changed files with 5 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -12,7 +12,7 @@ export enum Protocols {
}
export interface PointToPointProtocol {
multicodec: string;
multicodecs: string[];
peerStore: PeerStore;
peers: () => Promise<Peer[]>;
}