-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
JSON-RPC stdio server #3695
JSON-RPC stdio server #3695
Conversation
f3f9a5b
to
364902a
Compare
Added an example that creates an account, but we need to fix deltachat/yerpc#6 first before JSON-RPC is usable (fix deltachat/yerpc#22 is waiting for review). |
deltachat-server/Cargo.toml
Outdated
@@ -0,0 +1,26 @@ | |||
[package] | |||
name = "deltachat-server" | |||
version = "1.98.0" |
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.
rust 1.64 allows this to be done using workspace.package. not sure how eagerly we upgrade these days, and in any case probably not something for this PR
deltachat-server/rpc-client.py
Outdated
response = json.loads(line) | ||
if "id" in response: | ||
response_id = response["id"] | ||
event = self.request_events[response_id] |
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.
is it worth handling the potential KeyError
that could be raised here?
|
||
#[tokio::main(flavor = "multi_thread")] | ||
async fn main() -> Result<()> { | ||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); |
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.
fwiw might be worth using tracing for new things instead of env_logger
5a091fb
to
2aa80ba
Compare
ae80f1e
to
bb38e6c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
97abc4f
to
57dbdc9
Compare
57dbdc9
to
7da212d
Compare
This PR is ready for review, JSON-RPC node tests are ported from WebSocket to this stdio server. Python client is moved into #3734. |
426727f
to
b839e9c
Compare
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.
oh, nice! didn't realise this would completely eliminate the Arc and RwLock, that makes it certainly better.
@Simon-Laux @Jikstra I tried to keep things compatible and avoid breaking WebSocket example, so things are named to avoid conflicts with existing |
c90505b
to
4daaac7
Compare
It speaks JSON-RPC serialized into JSON Lines over stdio.
4daaac7
to
75ed4fe
Compare
deltachat-rpc-server
is a binary that speaks JSON-RPC protocol (the same as currently used by DeltaChat Desktop to interact with the core) over stdio. Requests are sent over stdin, responses and event notifications are printed on stdout, one JSON dictionary per line. This is similar to how Language Server Protocol works when Visual Studio Code or Emacs talks to clangd or rust-analyzer, actually even simpler.There is also an example python script in this PR that spawns a
deltachat-server
and calls a few methods asynchronously (via async-await). The plan is to move it into a separatedeltachat-client
python package.Advantages over existing Python bindings are:
json
andasyncio
libraries to spawn the process and exchange JSONs. It means pypi package can be uploaded to pypi without rebuilding it for each architecturedeltachat-rpc-server
binary can be distributed separately, you just need to throw it somewhere in the $PATH.