add conexion number control
This commit is contained in:
46
src/main.rs
46
src/main.rs
@@ -1,5 +1,7 @@
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::io::prelude::*;
|
||||
use crate::client::guard;
|
||||
|
||||
mod client;
|
||||
mod conf;
|
||||
mod protocol;
|
||||
@@ -8,30 +10,32 @@ fn main() {
|
||||
let listener = TcpListener::bind("127.0.0.1:25567").unwrap();
|
||||
let mut buf: [u8; 256] = [1; 256];
|
||||
let servers = conf::Servers::new();
|
||||
|
||||
let mut guard: guard::Guard = guard::Guard::new();
|
||||
for stream in listener.incoming() {
|
||||
match stream {
|
||||
Ok(mut stream) => {
|
||||
println!("Go!");
|
||||
let leng = stream.read(&mut buf).unwrap();
|
||||
let mut hs = protocol::HandShake::new(&mut buf[.. leng]);
|
||||
if hs.get_raw()[0] < 200 { //Filtra los ping, solo controlamos los handshakes
|
||||
match servers.get_server(&hs.getHostName()) {
|
||||
Some(s) => {
|
||||
hs.replace_port(s.1);
|
||||
let mut sstream = TcpStream::connect(s.0 + ":" + &s.1.to_string()).unwrap();
|
||||
println!("{}",hs.get_port());
|
||||
sstream.write(hs.get_raw());
|
||||
let c1 = client::Client::new(stream,sstream, hs);
|
||||
c1.start_proxy();
|
||||
},
|
||||
None => println!("No server found for{}", hs.getHostName())
|
||||
if guard.can_add(){
|
||||
match stream {
|
||||
Ok(mut stream) => {
|
||||
let leng = stream.read(&mut buf).unwrap();
|
||||
let mut hs = protocol::HandShake::new(&mut buf[.. leng]);
|
||||
if hs.get_raw()[0] < 200 { //Filtra los ping, solo controlamos los handshakes
|
||||
match servers.get_server(&hs.getHostName()) {
|
||||
Some(s) => {
|
||||
hs.replace_port(s.1);
|
||||
let mut sstream = TcpStream::connect(s.0 + ":" + &s.1.to_string()).unwrap();
|
||||
let p_id = sstream.local_addr().unwrap().port();
|
||||
println!("port4: {}",sstream.peer_addr().unwrap().port());
|
||||
sstream.write(hs.get_raw());
|
||||
let c1 = client::Client::new(stream,sstream, hs);
|
||||
guard.add_thread(c1.start_proxy());
|
||||
},
|
||||
None => println!("No server found for{}", hs.getHostName())
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
Err(_e) => println!("{}",_e),
|
||||
Err(_e) => println!("{}",_e),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user