mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-09 16:17:45 +00:00
refine code
This commit is contained in:
parent
1a5eeece6f
commit
4af656039e
4 changed files with 35 additions and 41 deletions
|
@ -5,6 +5,7 @@ use crate::tun2proxy::{
|
|||
};
|
||||
use std::collections::VecDeque;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Eq, PartialEq, Debug)]
|
||||
#[allow(dead_code)]
|
||||
|
@ -60,11 +61,11 @@ pub(crate) struct SocksConnection {
|
|||
client_outbuf: VecDeque<u8>,
|
||||
server_outbuf: VecDeque<u8>,
|
||||
data_buf: VecDeque<u8>,
|
||||
manager: std::rc::Rc<dyn ConnectionManager>,
|
||||
manager: Rc<dyn ConnectionManager>,
|
||||
}
|
||||
|
||||
impl SocksConnection {
|
||||
pub fn new(connection: &Connection, manager: std::rc::Rc<dyn ConnectionManager>) -> Self {
|
||||
pub fn new(connection: &Connection, manager: Rc<dyn ConnectionManager>) -> Self {
|
||||
let mut result = Self {
|
||||
connection: connection.clone(),
|
||||
state: SocksState::ServerHello,
|
||||
|
@ -302,14 +303,12 @@ impl ConnectionManager for Socks5Manager {
|
|||
fn new_connection(
|
||||
&self,
|
||||
connection: &Connection,
|
||||
manager: std::rc::Rc<dyn ConnectionManager>,
|
||||
) -> Option<std::boxed::Box<dyn TcpProxy>> {
|
||||
manager: Rc<dyn ConnectionManager>,
|
||||
) -> Option<Box<dyn TcpProxy>> {
|
||||
if connection.proto != smoltcp::wire::IpProtocol::Tcp.into() {
|
||||
return None;
|
||||
}
|
||||
Some(std::boxed::Box::new(SocksConnection::new(
|
||||
connection, manager,
|
||||
)))
|
||||
Some(Box::new(SocksConnection::new(connection, manager)))
|
||||
}
|
||||
|
||||
fn close_connection(&self, _: &Connection) {}
|
||||
|
@ -324,8 +323,8 @@ impl ConnectionManager for Socks5Manager {
|
|||
}
|
||||
|
||||
impl Socks5Manager {
|
||||
pub fn new(server: SocketAddr, credentials: Option<Credentials>) -> std::rc::Rc<Self> {
|
||||
std::rc::Rc::new(Self {
|
||||
pub fn new(server: SocketAddr, credentials: Option<Credentials>) -> Rc<Self> {
|
||||
Rc::new(Self {
|
||||
server,
|
||||
credentials,
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue