-
Notifications
You must be signed in to change notification settings - Fork 450
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
Idea: Protocol plugins, client/server capability handshake #337
Comments
It's a great idea! ShareDB needs this. |
Vague high-level brain dump: We'll need to think about what to do in non-happy handshake cases. For example, it may be acceptable to run without some plugins, but not without others. Even here, the server and client may disagree about what's important. In the case where a plugin isn't loaded, but this is deemed acceptable, it would be nice to inform the client, so they can eg alert the user about reduced functionality / prompt them to reload the page, etc. Similarly if an older version of a plugin is agreed upon, the client may want to handle this in some way. Plugins will need access to the instances of We may want to add some sort of formalised pubsub channel namespacing? And maybe a consistent format for middleware payloads? We'll also want to think about how plugins will be accessed. Do we recommend people extend the |
Rough ideas and notes from discussion today:
OT type negotiation:
|
You can keep the OT type version in sync with module.exports {
name: 'json0',
uri: 'http://sharejs.org/types/JSONv0',
version: process.env.npm_package_version,
} |
This change updates how the client and server communicate when first connecting, in a non-breaking way. ## Current behaviour - client creates and connects to a socket - client constructs a `Connection` object with the socket - the backend binds to the socket and constructs an `Agent` - the `Agent` sends an `init` message down the socket when constructed - the `Connection` receives the `init` message and initialises itself using information in the message ## Motivation for change There are currently a few things that would be nice to "negotiate" when a client connects. For example, clients may wish to: - the same `src` value when reconnecting, so that it persists as a stable "session ID" - set their default type - establish the exact versions of OT types being used - establish plugins and versions to use More detail can be found here: #337 ## New behaviour - client creates and connects to a socket - client constructs a `Connection` object with the socket - the backend binds to the socket and constructs an `Agent` - the `Agent` sends an `init` message down the socket when constructed - **new behaviour starts here** - the `Connection` checks the `init` message to see if the backend is capable of handshaking - if the backend _cannot_ handshake (ie it's old), then the client initialises itself as before - if the backend _can_ handshake, then it will disregard the `init` message, and send its own `hs` "handshake" message to the server - the backend receives the handshake message and sends a response - the `Connection` receives the new `hs` message and initialises itself using information in the message (like before, but with more or different information information) ## Other changes No changes have been made to the information being shared. In other words, this commit only updates the way in which the backend and the client communicate when first connecting. As a convenience for some tests, which had to be tweaked (because they assumed the connection was established immediately), this change also adds an optional `callback` parameter to `Backend.connect`, which will be invoked once the connection handshake completes.
These are some of my thoughts around enabling more extensibility of ShareDB and more rapid development of new ideas. I'm hoping to find some time in the next month or two to write a more fleshed out spec, but in the meantime, comments and more ideas are welcome!
ShareDB message protocol plugins
Over the past couple years, there have been new features that require extending the ShareDB message protocol with different
request.a
"actions":fetchSnapshotByTimestamp
These are handled in large switch statements:
I've been thinking it would be good to implement a framework for message protocol plugins, and refactor more optional features like queries,
fetchSnapshotByTimestamp
, and presence into plugins. This has some nice advantages:One of the requirements to accomplishing this is that clients and servers need to be able to do some sort of capability handshake, so they can agree on what protocol plugins to use for the session and at what versions.
Client/server capability handshake
I haven't put much thought into this yet. It could work like a simpler version of a TLS handshake. It would need to include at least:
Potential use cases for a capability handshake:
The text was updated successfully, but these errors were encountered: