mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-07 23:27:46 +00:00
create_new_tcp_connection_state
This commit is contained in:
parent
57851f029e
commit
d00a18c865
1 changed files with 13 additions and 14 deletions
|
@ -464,12 +464,8 @@ impl<'a> TunToProxy<'a> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let tcp_proxy_handler = tcp_proxy_handler?;
|
let tcp_proxy_handler = tcp_proxy_handler?;
|
||||||
self.create_new_tcp_proxy_connection(
|
let state = self.create_new_tcp_connection_state(server_addr, dst, tcp_proxy_handler)?;
|
||||||
server_addr,
|
self.connection_map.insert(connection_info.clone(), state);
|
||||||
dst,
|
|
||||||
tcp_proxy_handler,
|
|
||||||
connection_info.clone(),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
log::info!("Connect done {} ({})", connection_info, dst);
|
log::info!("Connect done {} ({})", connection_info, dst);
|
||||||
done = true;
|
done = true;
|
||||||
|
@ -518,10 +514,16 @@ impl<'a> TunToProxy<'a> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Another UDP packet
|
// Another UDP packet
|
||||||
let cm = self.get_connection_manager(&connection_info);
|
let manager = self.get_connection_manager(&connection_info);
|
||||||
if cm.is_none() {
|
if manager.is_none() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
let manager = manager.ok_or("")?;
|
||||||
|
let server_addr = manager.get_server_addr();
|
||||||
|
let tcp_proxy_handler = manager.new_tcp_proxy(&connection_info, true)?;
|
||||||
|
let state = self.create_new_tcp_connection_state(server_addr, dst, tcp_proxy_handler)?;
|
||||||
|
self.connection_map.insert(connection_info.clone(), state);
|
||||||
|
|
||||||
// TODO: Handle UDP packets
|
// TODO: Handle UDP packets
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -535,13 +537,12 @@ impl<'a> TunToProxy<'a> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_new_tcp_proxy_connection(
|
fn create_new_tcp_connection_state(
|
||||||
&mut self,
|
&mut self,
|
||||||
server_addr: SocketAddr,
|
server_addr: SocketAddr,
|
||||||
dst: SocketAddr,
|
dst: SocketAddr,
|
||||||
tcp_proxy_handler: Box<dyn TcpProxy>,
|
tcp_proxy_handler: Box<dyn TcpProxy>,
|
||||||
connection_info: ConnectionInfo,
|
) -> Result<TcpConnectState> {
|
||||||
) -> Result<()> {
|
|
||||||
let mut socket = tcp::Socket::new(
|
let mut socket = tcp::Socket::new(
|
||||||
tcp::SocketBuffer::new(vec![0; 1024 * 128]),
|
tcp::SocketBuffer::new(vec![0; 1024 * 128]),
|
||||||
tcp::SocketBuffer::new(vec![0; 1024 * 128]),
|
tcp::SocketBuffer::new(vec![0; 1024 * 128]),
|
||||||
|
@ -564,9 +565,7 @@ impl<'a> TunToProxy<'a> {
|
||||||
wait_read: true,
|
wait_read: true,
|
||||||
wait_write: false,
|
wait_write: false,
|
||||||
};
|
};
|
||||||
self.connection_map.insert(connection_info.clone(), state);
|
Ok(state)
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_to_server(&mut self, info: &ConnectionInfo) -> Result<(), Error> {
|
fn write_to_server(&mut self, info: &ConnectionInfo) -> Result<(), Error> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue