add server configuration

This commit is contained in:
2022-09-21 11:17:37 +02:00
parent 15aa4ec967
commit d10eba033f
84 changed files with 226 additions and 44 deletions

View File

@@ -1,30 +0,0 @@
use std::string;
pub struct HandShake<'a> {
len_pack: u8,
len_dom: u8,
datagram: &'a[u8],
host: &'a[u8],
port: &'a[u8],
}
impl<'a> HandShake<'a>{
pub fn new(data: &[u8]) -> HandShake {
let len_pack = data[0];
println!("{}", len_pack);
let len_dom = data[4];
println!("{}", len_dom);
HandShake {
len_pack: len_pack,
len_dom: len_dom,
datagram: data.clone(),
host: (&data[5 .. ((len_dom + 5) as usize)]).clone(),
port: (&data[((len_pack - 2) as usize) .. ((len_pack - 1) as usize)]).clone(),
}
}
pub fn getHostName(&self) -> String {
String::from_utf8(self.datagram[5 .. ((self.len_dom+5) as usize)].to_vec()).unwrap()
}
}

View File

@@ -3,26 +3,26 @@ use std::io::prelude::*;
use std::thread;
use std::sync::{Arc, Mutex, RwLock};
mod HandShake;
use crate::protocol;
pub struct Client<'a>{
client: Arc<Mutex<TcpStream>>,
server:Arc<Mutex<TcpStream>>,
//client: &'static TcpStream,
//server: &'static TcpStream,
hs: HandShake::HandShake<'a>,
hs: protocol::HandShake<'a>,
run : Arc<RwLock<bool>>,
//run: &'static bool
}
impl<'a> Client<'a> {
pub fn new(client: TcpStream, server: TcpStream, handshake: &[u8]) -> Client{
pub fn new(client: TcpStream, server: TcpStream, handshake: protocol::HandShake) -> Client{
Client {
client: Arc::new(Mutex::new(client)),
server: Arc::new(Mutex::new(server)),
//client: client,
//server: server,
hs: HandShake::HandShake::new(handshake),
hs: handshake,
run: Arc::new(RwLock::new(true)),
//run: &true,
}