-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
import type { IDecodedMessage, IDecoder } from "./message.js"; | ||
import type { | ||
Callback, | ||
PointToPointProtocol, | ||
ProtocolOptions, | ||
} from "./protocols.js"; | ||
import type { PointToPointProtocol } from "./protocols.js"; | ||
import type { IReceiver } from "./receiver.js"; | ||
|
||
export interface IFilter extends PointToPointProtocol { | ||
subscribe: <T extends IDecodedMessage>( | ||
decoders: IDecoder<T>[], | ||
callback: Callback<T>, | ||
opts?: ProtocolOptions | ||
) => Promise<() => Promise<void>>; | ||
} | ||
export type IFilter = IReceiver & PointToPointProtocol; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { IDecodedMessage, IDecoder } from "./message.js"; | ||
import type { Callback, ProtocolOptions } from "./protocols.js"; | ||
|
||
type Unsubscribe<T> = () => T; | ||
type PubSubTopic = string; | ||
type ContentTopic = string; | ||
|
||
export type ActiveSubscriptions = Map<PubSubTopic, ContentTopic[]>; | ||
|
||
export interface IReceiver { | ||
subscribe: <T extends IDecodedMessage>( | ||
decoders: IDecoder<T>[], | ||
callback: Callback<T>, | ||
opts?: ProtocolOptions | ||
) => Unsubscribe<void> | Promise<Unsubscribe<Promise<void>>>; | ||
getActiveSubscriptions: () => ActiveSubscriptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
import type { GossipSub } from "@chainsafe/libp2p-gossipsub"; | ||
import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types"; | ||
|
||
import type { IDecodedMessage, IDecoder } from "./message.js"; | ||
import type { Callback } from "./protocols.js"; | ||
import { IReceiver } from "./receiver.js"; | ||
import type { ISender } from "./sender.js"; | ||
|
||
type PubSubTopic = string; | ||
type ContentTopic = string; | ||
|
||
export type ActiveSubscriptions = Map<PubSubTopic, ContentTopic[]>; | ||
|
||
interface IRelayAPI { | ||
addObserver: <T extends IDecodedMessage>( | ||
decoder: IDecoder<T>, | ||
callback: Callback<T> | ||
) => () => void; | ||
getMeshPeers: () => string[]; | ||
getActiveSubscriptions: () => ActiveSubscriptions | undefined; | ||
readonly gossipSub: GossipSub; | ||
start: () => Promise<void>; | ||
unsubscribe: (pubSubTopic: string) => void; | ||
getMeshPeers: (topic?: TopicStr) => PeerIdStr[]; | ||
} | ||
|
||
export type IRelay = IRelayAPI & GossipSub & ISender; | ||
export type IRelay = IRelayAPI & ISender & IReceiver; |