-
Notifications
You must be signed in to change notification settings - Fork 8
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
Homeserver event stream #17
Comments
The But it also needs to unique, because a relay might be aggregating all these Events from multiple servers, and while the Timestamp tries to be globally unique, that is never granted or to be trusted ... some homeserver might deliberately choose clock-ids other chosen to confuse the relay, even if the clock-id bits are large enough. So maybe we should use the user ID / pubky as a part of the event id:
The downside of this is just more parsing, unless we keep the user Id in the A compromise might be to only add some of the user-id to break collision if/when they happen, on the relay side, for example:
This way we only add as few characters as needed for uniqueness, and the homeserver itself could use a u64 as keys without any uniqueness bytes or base32 encoding. Although that will cost more encoding on the fly. By adding The downside of this, is that you need to parse the |
Also a relay could calculate the longest matching leading bytes in all its pubkys, and use that to determine how many unique characters it needs to add after the timestamp in the |
Another way to make This encoding could also serve as a
|
A rudimentary version is implemented at #27, there is no realtime subscription api, but you can list URLs by their timestamp and paginate through them. |
Implemented a fire hose subscription in #54 ... no plans to add granular subscriptions yet. |
Goals
To decouple Indexers from Homeservers, and for general subscriptions/notifications usecases, we need an event stream interface that notify any subscriper that a resource has been updated.
Subscriptions need to a bit more dynamic than what we had in the web-relay (where you can only subscripe to exacte file), but it needs to be simple enough that the Homeserver doesn't need to do too much work to match data events to their subscriptions.
Users should be able to:
Design
Request
The API for subscriptions is suggested to be a concatenation of
<user pubky><prefix>
:Exact
orWildcard
Wildcard example:
Exact example:
Servers then store subscriptions in a key-value store, separtated to two logical tables (wildcards and exact ids), for example:
Once a new operation is done (PUT/DELETE), the server iterates over all wildcards and exact tables, until the prefixes no longer match the current event's path.
This way, the server only iterates over subscriptions that match the new event, instead of linearily checking all active subscriptions. More importantly these checks are lexographic so easy to reason about and compute.
Event
An event is encoded in a Server-Sent Events as follows:
event-id
: (u64 encoded as base32) is the sequence of the event internally to the server, which allows subscripers to resume after a disconnection from the lastSeq
they saw if the server didn't discard these old events.event type
:PUT
orDEL
user-id
: Pubkypath
: for example/pubky.app/potsts/XXXX
future data
: once we implement a copy-on-write Merkle Treap, we can also share theSeq
of the treap as a version of the file, and maybe the hash of the root or the hash of the value of the resource!Example
Subscribe to all events from a certain user.
Request
Response
Subscribe to all events in a named folder (or prefix of a path) from a certain user.
Request
Response
Subscribe to all events in a named folder (or prefix of a path) from all users.
Request
Response
Subscribe to all public events from everyone.
Request
Response
The text was updated successfully, but these errors were encountered: