feat: improved protocol definition

use session for authentication, then workspace to keep in sync and
subscribe to new buffers. Buffer service will dispatch live updates.
This commit is contained in:
əlemi 2022-07-30 14:35:38 +02:00
parent 2287793cd9
commit 4491482b0a
3 changed files with 33 additions and 9 deletions

View file

@ -1,4 +1,5 @@
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("proto/session.proto")?;
tonic_build::compile_protos("proto/workspace.proto")?; tonic_build::compile_protos("proto/workspace.proto")?;
tonic_build::compile_protos("proto/buffer.proto")?; tonic_build::compile_protos("proto/buffer.proto")?;
Ok(()) Ok(())

17
proto/session.proto Normal file
View file

@ -0,0 +1,17 @@
syntax = "proto3";
package session;
service Session {
rpc Create (SessionRequest) returns (SessionResponse);
rpc Join (SessionRequest) returns (SessionResponse);
rpc Leave (SessionRequest) returns (SessionResponse);
}
message SessionRequest {
optional string sessionKey = 1;
}
message SessionResponse {
string sessionKey = 1;
bool accepted = 2;
}

View file

@ -2,20 +2,26 @@ syntax = "proto3";
package workspace; package workspace;
service Workspace { service Workspace {
rpc Create (SessionRequest) returns (SessionResponse); rpc Buffers (WorkspaceRequest) returns (BufferList);
rpc Join (SessionRequest) returns (SessionResponse); rpc Push (BufferPayload) returns (WorkspaceResponse);
rpc Sync (SessionRequest) returns (SessionResponse); rpc Pull (BufferPayload) returns (BufferPayload);
rpc Leave (SessionRequest) returns (SessionResponse);
} }
message SessionRequest { message WorkspaceRequest {
string sessionKey = 1; string sessionKey = 1;
optional string content = 2;
} }
message SessionResponse { message WorkspaceResponse {
string sessionKey = 1; string sessionKey = 1;
bool accepted = 2; bool accepted = 2;
optional string hash = 3; }
optional string content = 4;
message BufferList {
repeated string path = 1;
}
message BufferPayload {
string sessionKey = 1;
string path = 2;
optional string content = 3;
} }