feat: add delegate() to connection

This commit is contained in:
2026-08-15 16:39:17 +02:00
parent 843903400d
commit 813a28402a

View File

@@ -4,6 +4,7 @@ use std::net::SocketAddr;
use log::{debug, error, warn};
use postcard::from_bytes;
use tokio::net::TcpSocket;
use tokio::{net::TcpStream, sync::mpsc::Sender};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
@@ -45,6 +46,7 @@ where
}
}
/// Meant for clients
pub async fn connect_to_server(&mut self, url: SocketAddr) -> bool {
match self.conn_type {
ConnectionType::Server => {
@@ -65,6 +67,18 @@ where
}
}
/// Meant for server
pub fn delegate(&mut self, tcp: TcpStream, client_addr: SocketAddr) -> bool {
match self.conn_type {
ConnectionType::Server => false, // only server can delegate
ConnectionType::Client => {
self.peer = Some(client_addr);
self.tcp = Some(tcp);
true
}
}
}
pub async fn send(&mut self, msg: Message<Outbound>) {
let size = msg.size;
let content = msg.content;