mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 08:45:38 +02:00
## Description Works in apptainer now.. podman is still the goat since apptainer needs docker treatment and even more.. - Added container detection so podman can be used to it's fullest, the non-sane ones are handled separately.. - Added video bit-depth option, cuz AV1 and 10-bit encoding go well together. - Some other package updates to nestri-server. - General tidying up of scripts to make multi-container-engine handling less of a pain. - Updated old wireplumber lua script to new json format. Further changes: - Removed unused debug arg from nestri-server. - Moved configs to config file folder rather than keeping them in containerfile. - Improved audio configs, moved some into wireplumber to keep things tidy. - Bit better arg handling in nestri-server. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Optional 10‑bit video support and auto‑launch of an app after display setup. * **Changes** * Standardized runtime/user env to NESTRI_* with updated home/cache paths and explicit LANG; password generation now logged. * Improved container/GPU detection and startup logging; reduced blanket root usage during startup; SSH setup surfaced. * WirePlumber/PipeWire moved to JSON configs; low‑latency clock and loopback audio policies added; audio capture defaults to PipeWire. * **Chores** * GStreamer/libp2p dependency upgrades and Rust toolchain pinned; NVIDIA driver capability exposed. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: DatCaptainHorse <DatCaptainHorse@users.noreply.github.com>
62 lines
2.1 KiB
Rust
62 lines
2.1 KiB
Rust
use byteorder::{BigEndian, ByteOrder};
|
|
use libp2p::futures::io::{ReadHalf, WriteHalf};
|
|
use libp2p::futures::{AsyncReadExt, AsyncWriteExt};
|
|
use std::sync::Arc;
|
|
use tokio::sync::Mutex;
|
|
|
|
const MAX_SIZE: usize = 1024 * 1024; // 1MB
|
|
|
|
pub struct SafeStream {
|
|
stream_read: Arc<Mutex<ReadHalf<libp2p::Stream>>>,
|
|
stream_write: Arc<Mutex<WriteHalf<libp2p::Stream>>>,
|
|
}
|
|
impl SafeStream {
|
|
pub fn new(stream: libp2p::Stream) -> Self {
|
|
let (read, write) = stream.split();
|
|
SafeStream {
|
|
stream_read: Arc::new(Mutex::new(read)),
|
|
stream_write: Arc::new(Mutex::new(write)),
|
|
}
|
|
}
|
|
|
|
pub async fn send_raw(&self, data: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
|
|
self.send_with_length_prefix(data).await
|
|
}
|
|
|
|
pub async fn receive_raw(&self) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
|
self.receive_with_length_prefix().await
|
|
}
|
|
|
|
async fn send_with_length_prefix(&self, data: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
|
|
if data.len() > MAX_SIZE {
|
|
return Err("Data exceeds maximum size".into());
|
|
}
|
|
|
|
let mut buffer = Vec::with_capacity(4 + data.len());
|
|
buffer.extend_from_slice(&(data.len() as u32).to_be_bytes()); // Length prefix
|
|
buffer.extend_from_slice(data); // Payload
|
|
|
|
let mut stream_write = self.stream_write.lock().await;
|
|
stream_write.write_all(&buffer).await?; // Single write
|
|
stream_write.flush().await?;
|
|
Ok(())
|
|
}
|
|
|
|
async fn receive_with_length_prefix(&self) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
|
let mut stream_read = self.stream_read.lock().await;
|
|
|
|
// Read length prefix + data in one syscall
|
|
let mut length_prefix = [0u8; 4];
|
|
stream_read.read_exact(&mut length_prefix).await?;
|
|
let length = BigEndian::read_u32(&length_prefix) as usize;
|
|
|
|
if length > MAX_SIZE {
|
|
return Err("Data exceeds maximum size".into());
|
|
}
|
|
|
|
let mut buffer = vec![0u8; length];
|
|
stream_read.read_exact(&mut buffer).await?;
|
|
Ok(buffer)
|
|
}
|
|
}
|