mirror of
https://github.com/Astatin3/unshell-nodes-rs.git
synced 2026-06-08 16:18:08 -06:00
38 lines
1.0 KiB
Rust
38 lines
1.0 KiB
Rust
use std::{net::SocketAddr, thread};
|
|
|
|
use crate::{
|
|
Error,
|
|
layers::LayerConfig,
|
|
networkers::{Connection, ServerTrait, TCPConnection, TCPServer, run_listener},
|
|
};
|
|
|
|
pub struct Node;
|
|
|
|
impl Node {
|
|
pub fn run(addr: SocketAddr) -> Result<(), Error> {
|
|
let layers = vec![LayerConfig::Handshake, LayerConfig::Base64];
|
|
|
|
run_listener(
|
|
TCPServer::bind(&addr)?,
|
|
layers,
|
|
|connection: Box<dyn Connection + Send + 'static>| {
|
|
thread::spawn(move || {
|
|
let mut connection = connection;
|
|
|
|
loop {
|
|
if let Ok(data) = connection.read() {
|
|
if !connection.is_alive() {
|
|
warn!("{} Disconnected!", connection.get_info());
|
|
break;
|
|
}
|
|
println!("Data: {}", data);
|
|
}
|
|
}
|
|
});
|
|
},
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
}
|