-
Notifications
You must be signed in to change notification settings - Fork 5
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
client-daemon communication via gRPC #62
Draft
Sophon96
wants to merge
8
commits into
main
Choose a base branch
from
tonic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9863798
feat(grpc): stub out basic client-to-daemon server
Sophon96 1a7d200
fix(grpc): install protoc before building daemon
Sophon96 af1edae
fix(actions): try to fix rust caching
Sophon96 d21d9a6
Revert "fix(actions): try to fix rust caching"
Sophon96 bbe5ef7
feat(grpc): implement basic grpc client in client and test event stre…
Sophon96 38b39b9
refactor: cleanup code
Sophon96 790cf83
fix(grpc): install protoc before building client
Sophon96 055a6a2
fix: format
Sophon96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
tonic_build::compile_protos("../proto/client_daemon.proto")?; | ||
println!("cargo:rerun-if-changed=migrations"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use client_daemon::client_daemon_server::ClientDaemon; | ||
use client_daemon::{ | ||
ChatHistoryRequest, ChatHistoryResponse, DeleteMessageRequest, DeleteMessageResponse, | ||
EditMessageRequest, EditMessageResponse, Event, SendMessageRequest, SendMessageResponse, | ||
}; | ||
use tokio_stream::wrappers::ReceiverStream; | ||
use tonic::{Request, Response, Status}; | ||
|
||
pub mod client_daemon { | ||
tonic::include_proto!("clientdaemon"); | ||
} | ||
|
||
#[derive(Debug)] | ||
// FIXME: name this something better | ||
pub struct ClientDaemonService {} | ||
|
||
#[tonic::async_trait] | ||
impl ClientDaemon for ClientDaemonService { | ||
async fn get_chat_history( | ||
&self, | ||
request: Request<ChatHistoryRequest>, | ||
) -> Result<Response<ChatHistoryResponse>, Status> { | ||
println!("Got chat history request: {:?}", request); | ||
|
||
// TODO: Implement returning chat history with database, etc. | ||
return Ok(Response::new(ChatHistoryResponse::default())); | ||
} | ||
|
||
type SubscribeToEventsStream = ReceiverStream<Result<Event, Status>>; | ||
|
||
async fn subscribe_to_events( | ||
&self, | ||
request: Request<()>, | ||
) -> Result<Response<Self::SubscribeToEventsStream>, Status> { | ||
println!("Received subscribe to events request: {:?}", request); | ||
// FIXME: Implement this | ||
let (_tx, rx) = tokio::sync::mpsc::channel(4); | ||
|
||
// TODO: send events as they come | ||
return Ok(Response::new(ReceiverStream::new(rx))); | ||
} | ||
|
||
async fn send_message( | ||
&self, | ||
request: Request<SendMessageRequest>, | ||
) -> Result<Response<SendMessageResponse>, Status> { | ||
println!("Received send message request: {:?}", request); | ||
|
||
// TODO: implement sending messages | ||
return Ok(Response::new(SendMessageResponse::default())); | ||
} | ||
|
||
async fn edit_message( | ||
&self, | ||
request: Request<EditMessageRequest>, | ||
) -> Result<Response<EditMessageResponse>, Status> { | ||
println!("Received edit message request: {:?}", request); | ||
|
||
// TODO: implement editing messages | ||
return Ok(Response::new(EditMessageResponse::default())); | ||
} | ||
|
||
async fn delete_message( | ||
&self, | ||
request: Request<DeleteMessageRequest>, | ||
) -> Result<Response<DeleteMessageResponse>, Status> { | ||
println!("Received delete message request: {:?}", request); | ||
|
||
// TODO: implement deleting messages | ||
return Ok(Response::new(DeleteMessageResponse::default())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
syntax = "proto3"; | ||
package clientdaemon; | ||
|
||
import "google/protobuf/empty.proto"; | ||
|
||
// Service for talking between the client and the daemon | ||
// TODO: Come up with a better name | ||
service ClientDaemon { | ||
// Get the chat history with some user | ||
rpc GetChatHistory(ChatHistoryRequest) returns (ChatHistoryResponse); | ||
|
||
// Subscribe to events emitted by the daemon | ||
rpc SubscribeToEvents(google.protobuf.Empty) returns (stream Event); | ||
|
||
// Send a message | ||
rpc SendMessage(SendMessageRequest) returns (SendMessageResponse); | ||
// Edit a message | ||
rpc EditMessage(EditMessageRequest) returns (EditMessageResponse); | ||
// Delete a message | ||
rpc DeleteMessage(DeleteMessageRequest) returns (DeleteMessageResponse); | ||
} | ||
|
||
// request to get chat history | ||
message ChatHistoryRequest { | ||
// user to get chat history with | ||
string username = 1; | ||
// id of last message received | ||
string last_id = 2; | ||
} | ||
|
||
// chat history with a user | ||
message ChatHistoryResponse { | ||
// all of the messages | ||
repeated Message messages = 1; | ||
} | ||
|
||
|
||
// An event emitted by the daemon | ||
message Event { | ||
// New or edited message | ||
message MessageEvent { | ||
// edited message | ||
bool edit = 1; | ||
// who sent it | ||
string sender = 2; | ||
// the message | ||
Message message = 3; | ||
} | ||
|
||
// Deleted message | ||
message MessageDeleteEvent { | ||
// who | ||
string sender = 1; | ||
// message id | ||
string id = 2; | ||
} | ||
|
||
// Other user request to talk | ||
message ChatRequestEvent { | ||
// user name of the user | ||
string username = 1; | ||
} | ||
|
||
oneof event { | ||
MessageEvent message = 1; | ||
MessageDeleteEvent message_delete = 2; | ||
ChatRequestEvent chat_request = 3; | ||
} | ||
} | ||
|
||
|
||
message SendMessageRequest { | ||
string recipient = 1; | ||
Message message = 2; | ||
} | ||
|
||
// Currently blank, just here for the future | ||
message SendMessageResponse {} | ||
|
||
|
||
message EditMessageRequest { | ||
string recipient = 1; | ||
Message message = 2; | ||
} | ||
|
||
// Currently blank, just here for the future | ||
message EditMessageResponse {} | ||
|
||
message DeleteMessageRequest { | ||
string recipient = 1; | ||
Message message = 2; | ||
} | ||
|
||
// Currently blank, just here for the future | ||
message DeleteMessageResponse {} | ||
|
||
message Message { | ||
string id = 1; | ||
uint64 timestamp = 2; | ||
string user = 3; | ||
string content = 4; | ||
// TODO: figure out how to do attachments | ||
// repeated bytes attachments = 5; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It looks like you implement the connection here, is it work?
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.
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.
Yep! If you run it, you can use a gRPC client like BloomRPC and import
proto/client_daemon.proto
and fire off RPC calls, though all of them are just blank for now.