Files
AstralRinth/apps/labrinth/src/common/networking/message.rs
Josiah Glosson 650ab71a83 Commonized networking (#3310)
* Fix not being able to connect to local friends socket

* Start basic work on tunneling protocol and move some code into a common crate

* Commonize message serialization logic

* Serialize Base62Ids as u64 when human-readability is not required

* Move ActiveSockets tuple into struct

* Make CI run when rust-common is updated

CI is currently broken for labrinth, however

* Fix theseus-release.yml to reference itself correctly

* Implement Labrinth side of tunneling

* Implement non-friend part of theseus tunneling

* Implement client-side except for socket loop

* Implement the socket loop

Doesn't work though. Debugging time!

* Fix config.rs

* Fix deadlock in labrinth socket handling

* Update dockerfile

* switch to workspace prepare at root level

* Wait for connection before tunneling in playground

* Move rust-common into labrinth

* Remove rust-common references from Actions

* Revert "Update dockerfile"

This reverts commit 3caad59bb474ce425d0b8928d7cee7ae1a5011bd.

* Fix Docker build

* Rebuild Theseus if common code changes

* Allow multiple connections from the same user

* Fix test building

* Move FriendSocketListening and FriendSocketStoppedListening to non-panicking TODO for now

* Make message_serialization macro take varargs for binary messages

* Improve syntax of message_serialization macro

* Remove the ability to connect to a virtual socket, and disable the ability to listen on one

* Allow the app to compile without running labrinth

* Clippy fix

* Update Rust and Clippy fix again

---------

Co-authored-by: Jai A <jaiagr+gpg@pm.me>
2025-02-28 10:52:47 -08:00

66 lines
1.3 KiB
Rust

use crate::common::ids::UserId;
use crate::common::users::UserStatus;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ClientToServerMessage {
StatusUpdate {
profile_name: Option<String>,
},
SocketListen {
socket: Uuid,
},
SocketClose {
socket: Uuid,
},
SocketSend {
socket: Uuid,
#[serde(with = "serde_bytes")]
data: Vec<u8>,
},
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ServerToClientMessage {
StatusUpdate {
status: UserStatus,
},
UserOffline {
id: UserId,
},
FriendStatuses {
statuses: Vec<UserStatus>,
},
FriendRequest {
from: UserId,
},
FriendRequestRejected {
from: UserId,
},
FriendSocketListening {
user: UserId,
socket: Uuid,
},
FriendSocketStoppedListening {
user: UserId,
},
SocketConnected {
to_socket: Uuid,
new_socket: Uuid,
},
SocketClosed {
socket: Uuid,
},
SocketData {
socket: Uuid,
#[serde(with = "serde_bytes")]
data: Vec<u8>,
},
}