Skip to content

Working example of the chat using quic,protobuf and actix #16

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

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
42fb9ad
Initialize the project structure with separate crates for server and …
r-zig Apr 30, 2025
d0a6a7d
add pre-commit hook + script and readme update
r-zig Apr 30, 2025
f327c42
set authors
r-zig May 1, 2025
a557400
add protobuf declaration and generated crate with some utility functions
r-zig May 1, 2025
69a4c87
move default room to the builders
r-zig May 1, 2025
c88a088
add builders for the Join , Leave and Chat messages
r-zig May 1, 2025
87046dc
Add error code and return error code instead of strings
r-zig May 1, 2025
5005048
reuse header builder
r-zig May 1, 2025
c13ef27
update readme with protobuf dependencies
r-zig May 1, 2025
f932022
reduce prost version to "0.12" - the newer version does not compile w…
r-zig May 7, 2025
1e50b46
Server implementation v1
r-zig May 7, 2025
21a9bfc
first integration test with duplicate join user
r-zig May 10, 2025
6002407
update protobuf-stream to use the github repo instead of local develo…
r-zig May 10, 2025
111302c
create broadcast test, currently sometimes failed because of connecti…
r-zig May 10, 2025
aea686a
Fix connection lost with default keep alive and idle timeouts
r-zig May 10, 2025
a864e58
implement client
r-zig May 10, 2025
847898a
Create rust.yml
r-zig May 10, 2025
1896b3f
Update rust.yml
r-zig May 10, 2025
09393e4
rename to chat-client
r-zig May 10, 2025
d839e7d
run both server & client
r-zig May 10, 2025
8bee0b1
rename to chat-client
r-zig May 10, 2025
f4861f1
fix server address to listen on all network interfaces
r-zig May 10, 2025
7b927bf
add log to the action
r-zig May 10, 2025
e311c1e
Fix Non recoverable error occurred on leave
r-zig May 10, 2025
0db8ade
add debug for client
r-zig May 10, 2025
4ecc3c3
Add screen recording video example of using the server with multiple …
r-zig May 10, 2025
e639222
change order of tests and client call
r-zig May 10, 2025
28ddee3
add converted gif of the demo video
r-zig May 10, 2025
c97a2ea
rename client server to server-addr
r-zig May 10, 2025
8bb9455
update videos with client server address
r-zig May 10, 2025
ef25120
update readme
r-zig May 10, 2025
4c9be10
how to run tests
r-zig May 10, 2025
ec7bb37
update chat-client cmd
r-zig May 11, 2025
a2905a0
update client command in the workflow
r-zig May 11, 2025
a550a2f
print connected and send join instead of info log
r-zig May 11, 2025
1aa497c
set RUST_LOG env var for client
r-zig May 11, 2025
9681f01
add client logging
r-zig May 11, 2025
2342585
redirect server logs to file and try to find the join log message
r-zig May 11, 2025
8bf8579
add debugging for leave message
r-zig May 11, 2025
fae9192
remove webm video
r-zig May 11, 2025
5d93d06
clean code
r-zig May 12, 2025
17a65c6
fix debug args
r-zig May 12, 2025
2417b88
fix ci
r-zig May 12, 2025
162d81a
fix ci, don't wait forever to the server
r-zig May 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Rust

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Install protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Start Chat Server
run: |
cargo run --bin server -- --listen 0.0.0.0:4433 > server.log &
SERVER_PID=$!
sleep 5
if ! ps -p $SERVER_PID > /dev/null; then
echo "Server failed to start."
exit 1
fi
env:
RUST_LOG: debug
- name: wait server to start
run: sleep 5
- name: Run tests
run: cargo test --verbose
- name: Test Chat Client with Interactive Input
run: |
cargo run --bin chat-client -- --server-addr 127.0.0.1:4433 --server-name localhost --name test-client
if [ $? -ne 0 ]; then
echo "Client exited with a failure."
exit 1
fi
env:
RUST_LOG: debug
- name: Check Logs for Specific String
run: |
if ! grep "User test-client joined" server.log; then
echo "String not found in logs. No evidence to client messages to the server. Halting workflow."
exit 1
fi
11 changes: 11 additions & 0 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

echo "Running cargo fmt..."
cargo fmt -- --check

echo "Running cargo check..."
cargo check

echo "Running cargo clippy..."
cargo clippy -- -D warnings
133 changes: 133 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'server'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=server"
],
"filter": {
"name": "server",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'chat_contract'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=chat-contract"
],
"filter": {
"name": "chat_contract",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'server'",
"cargo": {
"args": [
"build",
"--bin=server",
"--package=chat-server",
],
"filter": {
"name": "server",
"kind": "bin"
}
},
"args": [
"--listen",
"127.0.0.1:4433"
],
"cwd": "${workspaceFolder}",
"env": {
"RUST_LOG": "debug" // Set the RUST_LOG environment variable
}
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'client'",
"cargo": {
"args": [
"build",
"--bin=chat-client",
"--package=chat-client"
],
"filter": {
"name": "chat-client",
"kind": "bin"
}
},
"args": [
"--server-addr",
"127.0.0.1:4433",
"--server-name",
"localhost",
"--name",
"test-client-debugger",
],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'client-cli'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=client-cli",
"--package=client-cli"
],
"filter": {
"name": "client-cli",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'common'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=common"
],
"filter": {
"name": "common",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
resolver = "2"
members = [
"server",
"client",
"chat-contract"
]
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,48 @@ without error, and is free of clippy errors.
send a message to the server from the client. Make sure that niether the server
or client exit with a failure. This action should be run anytime new code
is pushed to a branch or landed on the main branch.

### Demo
![Demo](assets/example-server-clients.gif)

## Getting Started

### 1. Install Git Pre-Commit Hook

To ensure all code is formatted, compiles correctly, and passes Clippy checks before committing, run the following script once after cloning the repository:

```bash
bash scripts/install-hooks.sh
```
### 2. Install Protocol Buffers (protoc)
This project uses Protocol Buffers (Protobuf) for serializing structured data. In order to compile .proto files, you need to have the protoc compiler installed.

Follow the instructions for your operating system here:
https://protobuf.dev/installation/

Make sure protoc is available in your PATH:
```bash
protoc --version
```
Should output something like: libprotoc 3.21.12

Note: Some components of this project might auto-generate code from .proto files during the build process. Ensure protoc is installed and accessible before building or running the project.

### 3. Run Server
```bash
cargo run --bin server
```

### 4. Run Client
```bash
cargo run --bin chat-client -- --server-addr 127.0.0.1:4433 --server-name localhost --name test-client
```

### 4. Run Tests
```bash
cargo run --bin server
```
In other terminal
```bash
cargo test
```
Binary file added assets/example-server-clients.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions chat-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "chat-contract"
version = "0.1.0"
edition = "2021"
authors = ["Ron Zigelman <[email protected]>"]

[dependencies]
prost = "0.12"
prost-types = "0.12"
uuid = { version = "1.16.0", features = ["v4"] }

[build-dependencies]
prost-build = "0.12"
5 changes: 5 additions & 0 deletions chat-contract/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use std::io::Result;
fn main() -> Result<()> {
prost_build::compile_protos(&["../proto/chat.proto"], &["../proto/"])?;
Ok(())
}
Loading