-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: add and implement IReceiver #1219
Conversation
Currently this PR is for just showing possible approach. In general I think since we are using There are different things we can choose or continue using (callbacks, Promises, events etc). I would like to highlight this - RxJS. Usage of the lib on that level will help us:
If our common opinion would be to continue current approach it definitely makes sense to make interfaces are compatible (this work waku-org/js-noise#14) and try to come up with common approach for events that are owned by us (similarly to it #1213). |
I think using RxJS for the receiver interface is fair and should hopefully help with js-noise and other consumers. |
I've been playing with idea of In short - their usage will provide some extra features to consumers such as error handling but it is not clear if it will be used by anyone. The other problem it will introduce a dependency and given that our bundle is quite big already it's better to add after this issue #579 is done. I propose to refrain from using Do you even think it worth investigating, @fryorcraken? |
We could have an issue in the icebox. As js-waku adoption grows, it may become a request from developers and in this case we could review. |
packages/core/src/lib/relay/index.ts
Outdated
addObserver<T extends IDecodedMessage>( | ||
decoder: IDecoder<T>, | ||
public subscribe<T extends IDecodedMessage>( | ||
decoders: IDecoder<T>[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes subscribe
unified and accept decoders
instead of one decoder.
size-limit report 📦
|
packages/interfaces/src/receiver.ts
Outdated
decoders: IDecoder<T>[], | ||
callback: Callback<T>, | ||
opts?: ProtocolOptions | ||
) => Unsubscribe<void> | Promise<Unsubscribe<Promise<void>>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another thing I want to figure out - either make it sync or async for the interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it is expected to have both:
- Relay: all actions are local as the node relays all messages of the pubsub topic so listening (subscribe) or stopping to listen (unsubscribe) to given content topics are local actions hence it's sync
- Filter: filtering of subscription is done by remote node, hence it's async
I don't see the dichotomy as an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that types are not reliable - we don't know if subscribe
should be awaited or not, same goes for Unsubscribe
.
packages/interfaces/src/receiver.ts
Outdated
decoders: IDecoder<T>[], | ||
callback: Callback<T>, | ||
opts?: ProtocolOptions | ||
) => Unsubscribe<void> | Promise<Unsubscribe<Promise<void>>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it is expected to have both:
- Relay: all actions are local as the node relays all messages of the pubsub topic so listening (subscribe) or stopping to listen (unsubscribe) to given content topics are local actions hence it's sync
- Filter: filtering of subscription is done by remote node, hence it's async
I don't see the dichotomy as an issue.
return new WakuNode( | ||
options ?? {}, | ||
libp2p, | ||
undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea for following improvement: make builders be props of protocolOptions
object.
…lready initialized gossipSub
return (libp2p: Libp2p) => new Relay(libp2p, init); | ||
} | ||
|
||
export function wakuGossipSub( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a consequence of gossipSub
being a property and not an extension of the Relay
.
My opinion - it makes sense because Relay
is our abstraction and GossipSub
is a tool that we use to implement what we need.
cc: @fryorcraken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see how it is. I think it's fine for now. We can iterate on the API as we use it and get more feedback.
return (libp2p: Libp2p) => new Relay(libp2p, init); | ||
} | ||
|
||
export function wakuGossipSub( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see how it is. I think it's fine for now. We can iterate on the API as we use it and get more feedback.
Problem
We have
Relay
andFilter
that have the same behaviour but do not share common interface. It makes harder to make interchangeable usage of these objects.Solution
Create and implement
IReceiver
Notes