Skip to content

Commit ec49e5d

Browse files
Refactor libgsh to split client and server features
Reorganized libgsh by separating client and server functionality into distinct modules, replacing the previous async/simple structure. Introduced new codecs and handshake logic for both client and server, updated example dependencies to use the 'server' feature, and removed obsolete async and sync modules. Updated imports and usage throughout the codebase to reflect the new structure, improving maintainability and feature isolation.
1 parent 92d50c6 commit ec49e5d

31 files changed

Lines changed: 517 additions & 1119 deletions

File tree

client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ webpki-roots = "0.26.8"
1111
# NOTE: The SDL3 Rust binding crate and feature names may differ; if this crate name/version
1212
# doesn't exist in your registry, update to the correct crate (for example `sdl3`, `sdl3-sys`,
1313
# or a specific git repo). This change is the first step to migrate code to SDL3.
14-
# Use sdl3 with a couple features enabled; adjust if you need different feature set.
14+
# Use sdl3 with a couple of features enabled; adjust if you need different feature set.
1515
sdl3 = { version = "0.16.1", features = [
1616
"build-from-source",
1717
"static-link",

client/src/config.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
use std::fs::File;
2-
use std::io::Write;
3-
use std::path::PathBuf;
4-
use std::{collections::HashMap, io::Read};
5-
61
use homedir::my_home;
7-
use libgsh::cert;
8-
use libgsh::rsa::rand_core::OsRng;
9-
use libgsh::rsa::{RsaPrivateKey, RsaPublicKey};
2+
use libgsh::{
3+
rsa::{rand_core::OsRng, RsaPrivateKey, RsaPublicKey},
4+
shared::cert,
5+
};
106
use serde::{Deserialize, Serialize};
7+
use std::{
8+
collections::HashMap,
9+
fs::File,
10+
io::{Read, Write},
11+
path::PathBuf,
12+
};
1113

1214
fn gsh_dir() -> PathBuf {
1315
let mut path = my_home()
@@ -27,7 +29,7 @@ pub struct KnownHost {
2729
}
2830

2931
impl KnownHost {
30-
/// Check if the provided fingerprints contains all of the known fingerprints
32+
/// Check if the provided fingerprints contains all the known fingerprints
3133
pub fn compare(&self, fingerprints: &[Vec<u8>]) -> bool {
3234
self.fingerprints
3335
.iter()

client/src/network.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
use std::sync::Arc;
2-
1+
use crate::{auth::ClientAuthProvider, config};
32
use dialoguer::Confirm;
4-
use libgsh::sha2::{Digest, Sha256};
5-
use libgsh::shared::{
6-
protocol::{self, client_hello::MonitorInfo, status_update::StatusType, ServerHelloAck},
7-
r#async::AsyncMessageCodec,
3+
use libgsh::{
4+
sha2::{Digest, Sha256},
5+
shared::{
6+
codec::{GshStreamClient, GshStreamServer},
7+
protocol::{
8+
client_hello::MonitorInfo, status_update::StatusType, ServerHelloAck, StatusUpdate,
9+
},
10+
},
811
};
12+
use std::sync::Arc;
913
use tokio::{io::AsyncWriteExt, net::TcpStream};
1014
use tokio_rustls::rustls::{
1115
self,
1216
client::danger::{ServerCertVerified, ServerCertVerifier},
1317
crypto::{ring as provider, CryptoProvider},
1418
time_provider,
1519
};
16-
// use std::{net::TcpStream, sync::Arc};
17-
use tokio_rustls::{client::TlsStream, TlsConnector};
18-
19-
use crate::{auth::ClientAuthProvider, config};
20-
21-
// pub type Messages = MessageCodec<StreamOwned<ClientConnection, TcpStream>>;
22-
pub type Messages = AsyncMessageCodec<TlsStream<TcpStream>>;
20+
use tokio_rustls::TlsConnector;
2321

24-
pub async fn shutdown_tls(messages: &mut Messages) -> anyhow::Result<()> {
22+
pub async fn shutdown_tls(stream: &mut GshStreamServer) -> anyhow::Result<()> {
2523
log::trace!("Exiting gracefully...");
26-
messages.get_stream().get_mut().1.send_close_notify();
27-
messages
28-
.write_event(protocol::StatusUpdate {
24+
stream.get_inner().get_mut().1.send_close_notify();
25+
stream
26+
.send(StatusUpdate {
2927
kind: StatusType::Exit as i32,
3028
details: None,
3129
})
3230
.await?;
33-
messages.get_stream().get_mut().0.shutdown().await?;
31+
stream.get_inner().get_mut().0.shutdown().await?;
3432
log::trace!("Connection closed.");
3533
Ok(())
3634
}
@@ -121,7 +119,7 @@ pub async fn connect_tls(
121119
mut known_hosts: config::KnownHosts,
122120
id_files: config::IdFiles,
123121
id_override: Option<String>,
124-
) -> anyhow::Result<(ServerHelloAck, Messages)> {
122+
) -> anyhow::Result<(ServerHelloAck, GshStreamClient)> {
125123
let server_name = host.to_string().try_into()?;
126124
let tls_config = Arc::new(tls_config(insecure)?);
127125
let tls_connector = TlsConnector::from(tls_config);
@@ -137,8 +135,8 @@ pub async fn connect_tls(
137135
return Err(anyhow::anyhow!("Host verification failed."));
138136
}
139137
}
140-
let mut messages = Messages::new(tls_stream);
141-
let hello = libgsh::shared::r#async::handshake_client(
138+
let mut messages = GshStreamClient::new(tls_stream);
139+
let hello = libgsh::client::handshake(
142140
&mut messages,
143141
monitors,
144142
ClientAuthProvider::new(known_hosts, id_files, id_override),

examples/colors/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
libgsh = { workspace = true }
7+
libgsh = { workspace = true, features = ["server"] }
88
rand = "0.9.1"
99
log = "0.4.27"
1010
env_logger = "0.11.8"

examples/cube/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
libgsh = { workspace = true }
7+
libgsh = { workspace = true, features = ["server"] }
88
vek = "0.17.1"
99
log = "0.4.27"
1010
env_logger = "0.11.8"

examples/liquid_sim/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
libgsh = { workspace = true }
7+
libgsh = { workspace = true, features = ["server"] }
88
glam = "0.29.2"
99
log = "0.4.27"
1010
env_logger = "0.11.8"

examples/password_auth/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
libgsh = { workspace = true }
7+
libgsh = { workspace = true, features = ["server"] }
88
log = "0.4.27"
99
env_logger = "0.11.8"

examples/password_auth/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
.format_target(false)
1818
.format_timestamp(None)
1919
.init();
20-
let (key, private_key) = libgsh::cert::self_signed(&["localhost"]).unwrap();
20+
let (key, private_key) = libgsh::shared::cert::self_signed(&["localhost"]).unwrap();
2121
let config = libgsh::tokio_rustls::rustls::ServerConfig::builder()
2222
.with_no_client_auth()
2323
.with_single_cert(vec![key.cert.der().clone()], private_key)

examples/remote_desktop/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
libgsh = { workspace = true }
7+
libgsh = { workspace = true, features = ["server"] }
88
log = "0.4.27"
99
env_logger = "0.11.8"
1010
xcap = { version = "0.5.1", features = ["image"] }

examples/remote_desktop/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use libgsh::{
22
async_trait::async_trait,
3-
cert,
4-
frame::full_frame_segment,
5-
r#async::{
3+
server::{
64
server::AsyncServer,
75
service::{AsyncService, AsyncServiceExt},
86
Messages,
97
},
8+
shared::cert,
9+
shared::frame::full_frame_segment,
1010
shared::protocol::{
1111
client_message,
1212
server_hello_ack::{self, window_settings, FrameFormat, WindowSettings, ZstdCompression},

0 commit comments

Comments
 (0)