Skip to content
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

subscription interface and event streaming for low latency push events #508

Closed
wants to merge 31 commits into from

Conversation

andorsk
Copy link
Contributor

@andorsk andorsk commented Sep 19, 2023

TP here: https://hackmd.io/vrC1iCudTVuM8nryo3QQKA#Subscribing-to-your-own-Node

A few things I want to clarify here:

  1. Subscriptions are not limited to WRITE events. Subscriptions are generalized to an event stream, which is allows you to stream EventMessages into the stream. The EventStream will emit events. You can build EventStreams with filters to build a dynamic pipeline for listeners.
  2. Scopes are not implemented yet ( for filters and event scope ), but will be implemented soon.
  3. There's some conversation about how grant authorization works on a persistent stream.

SubscriptionRequest returns an EventEmitter, which is what a dwn will listen to for streaming events.

sequenceDiagram
  participant Bob
  participant Alice 
  participant EventStream 

  loop Permission Grant Flow
    Bob -->> Alice : Permission Grant of type SubscriptionRequest
    note left of Alice: authorizes or rejects
    Alice -->> Bob : Permission Grant sent back with SubscriptionRequest scope
  end
  loop Subscription Flow 
    Bob -->> Alice : Subscription Request to Alice
    note left of Alice : validates

    EventStream --> Alice : subscriptionRequestHandler returns an Event Stream to Alice
    Alice -->> Alice : action such as writes to Dwn. processMessage sends Event to EventStream
    Alice -->> EventStream : event stream receives message and emits it over "event" channel
    EventStream -->> EventStream : subscriptions chains events over eventstream. 
    EventStream -->> Alice : emits filtered event to Alice if found. 
    Alice -->> Bob: sends to Bob
  end
Loading

Note: the dwn-sdk-js is not in charge of actually managing the connection between Alice and Bob. Alice is simply getting an "event hook" to listen into that is scoped to a subscription request. She then can choose to send it or not.

I have an update to dwn-server to handle the web socket connections coming.

State: Initial feedback would be helpful, but not ready for merging yet.

@andorsk andorsk marked this pull request as draft September 19, 2023 18:02
@andorsk andorsk changed the title Ask/pubsub pub/sub interfaces Sep 19, 2023
@andorsk andorsk force-pushed the ask/pubsub branch 2 times, most recently from a94fb25 to 12601c3 Compare September 27, 2023 09:47
@andorsk andorsk changed the title pub/sub interfaces subscription interface and event streaming Sep 27, 2023
@andorsk andorsk changed the title subscription interface and event streaming subscription interface and event streaming for low latency push events Sep 27, 2023
Copy link
Member

@LiranCohen LiranCohen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left a few small nits, and a comment about signing the event log messages.

// },
// authorizationSignatureInput : Jws.createSignatureInput(tennat),
// })
// this.config.eventStream.add(logMessage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity: I don't think we're not able to sign here because EventLog.append() is called from within the handler after the message has already been signed and received by the DWN.

But I think you're right, not sure we need to sign this at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea...i fixed this by just forwarding the message itself for now.


export type EventCreateOptions = {
descriptor: EventDescriptor;
messageId?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
messageId?: string;
messageCid?: string;

interface : DwnInterfaceName.Subscriptions,
method : DwnMethodName.Request,
messageTimestamp : options.messageTimestamp ?? getCurrentTimeInHighPrecision(),
messageId : options.messageId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
messageId : options.messageId,
messageCid : options. messageCid,

method: DwnMethodName.Request;
messageTimestamp: string;
messageId?: string; // attached message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
messageId?: string; // attached message
messageCid?: string; // attached message

@LiranCohen
Copy link
Member

Closing, this work has been migrated to: #607

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants