smoltcp updates breaking changes fix
This commit is contained in:
@@ -80,7 +80,7 @@ impl TcpConnection {
|
||||
(conn, rx_from_smol, tx_to_smol, handshake_tx)
|
||||
}
|
||||
|
||||
pub fn tick(&mut self, socket: &mut tcp::Socket) -> bool {
|
||||
pub fn tick(&mut self, socket: &mut tcp::Socket, timestamp: smoltcp::time::Instant) -> bool {
|
||||
match self.state {
|
||||
ConnectionState::Handshaking => {
|
||||
if let Some(rx) = &mut self.handshake_rx {
|
||||
@@ -103,7 +103,7 @@ impl TcpConnection {
|
||||
}
|
||||
|
||||
ConnectionState::Active => {
|
||||
self.poll_and_process(socket);
|
||||
self.poll_and_process(socket, timestamp);
|
||||
|
||||
if matches!(socket.state(), tcp::State::Closed | tcp::State::TimeWait) {
|
||||
debug!(%self.core.handle, "TCP Socket is finished, state -> Closed");
|
||||
@@ -129,14 +129,14 @@ impl TcpConnection {
|
||||
true
|
||||
}
|
||||
|
||||
fn poll_and_process(&mut self, socket: &mut tcp::Socket) {
|
||||
fn poll_and_process(&mut self, socket: &mut tcp::Socket, timestamp: smoltcp::time::Instant) {
|
||||
let current_rtt = GLOBAL_MIN_RTT.load(Ordering::Relaxed);
|
||||
let rtt = smoltcp::time::Duration::from_millis(current_rtt as u64);
|
||||
socket.set_tunnel_rtt(rtt);
|
||||
|
||||
// Читаем из браузера в Туннель
|
||||
while socket.can_recv() && self.core.tx.capacity() > 0 {
|
||||
if let Ok(n) = socket.peek_slice(&mut self.chunk_buf) {
|
||||
if let Ok(n) = socket.peek_slice(&mut self.chunk_buf, timestamp) {
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
@@ -283,14 +283,14 @@ impl UdpConnection {
|
||||
.map_or(false, |ep| ep.port == port)
|
||||
}
|
||||
|
||||
pub fn tick(&mut self, socket: &mut udp::Socket) -> bool {
|
||||
pub fn tick(&mut self, socket: &mut udp::Socket, timestamp: smoltcp::time::Instant) -> bool {
|
||||
if self.last_activity.elapsed() > UDP_IDLE_TIMEOUT {
|
||||
socket.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if socket.can_recv() {
|
||||
while let Ok((data, metadata)) = socket.recv() {
|
||||
while let Ok((data, metadata)) = socket.recv(timestamp) {
|
||||
if let smoltcp::wire::IpAddress::Ipv4(ip) = metadata.endpoint.addr {
|
||||
self.last_client_endpoint = Some(metadata.endpoint);
|
||||
let target_ip = std::net::Ipv4Addr::from(ip);
|
||||
@@ -363,12 +363,12 @@ use smoltcp::socket::icmp;
|
||||
pub struct IcmpResponder;
|
||||
|
||||
impl IcmpResponder {
|
||||
pub fn handle(socket: &mut icmp::Socket) {
|
||||
pub fn handle(socket: &mut icmp::Socket, timestamp: smoltcp::time::Instant) {
|
||||
if !socket.can_recv() {
|
||||
return;
|
||||
}
|
||||
|
||||
let result = socket.recv();
|
||||
let result = socket.recv(timestamp);
|
||||
|
||||
if let Ok((data, src_addr)) = result {
|
||||
let payload = data.to_vec();
|
||||
|
||||
@@ -253,21 +253,26 @@ impl ConnectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_sockets(&mut self, socket_set: &mut SocketSet) {
|
||||
pub fn process_sockets(&mut self, socket_set: &mut SocketSet, now: smoltcp::time::Instant) {
|
||||
let handles: Vec<SocketHandle> = socket_set.iter().map(|(h, _)| h).collect();
|
||||
|
||||
for handle in handles {
|
||||
let socket = socket_set.get_mut(handle);
|
||||
|
||||
match socket {
|
||||
Socket::Tcp(s) => self.handle_tcp(handle, s),
|
||||
Socket::Udp(s) => self.handle_udp(handle, s),
|
||||
Socket::Icmp(s) => IcmpResponder::handle(s),
|
||||
Socket::Tcp(s) => self.handle_tcp(handle, s, now), // Пробрасываем в TCP
|
||||
Socket::Udp(s) => self.handle_udp(handle, s, now), // Пробрасываем в UDP
|
||||
Socket::Icmp(s) => IcmpResponder::handle(s, now), // Пробрасываем в ICMP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_tcp(&mut self, handle: SocketHandle, socket: &mut tcp::Socket) {
|
||||
// Добавляем аргумент 'now' в сигнатуру
|
||||
fn handle_tcp(
|
||||
&mut self,
|
||||
handle: SocketHandle,
|
||||
socket: &mut tcp::Socket,
|
||||
now: smoltcp::time::Instant,
|
||||
) {
|
||||
self.tracker.update_activity(handle);
|
||||
let state = socket.state();
|
||||
|
||||
@@ -301,14 +306,21 @@ impl ConnectionManager {
|
||||
}
|
||||
|
||||
if let Some(conn) = self.tracker.get_tcp_mut(handle) {
|
||||
let _ = conn.tick(socket);
|
||||
// Передаем 'now' в метод tick для обработки очередей и RTT
|
||||
let _ = conn.tick(socket, now);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_udp(&mut self, handle: SocketHandle, socket: &mut udp::Socket) {
|
||||
fn handle_udp(
|
||||
&mut self,
|
||||
handle: SocketHandle,
|
||||
socket: &mut udp::Socket,
|
||||
now: smoltcp::time::Instant,
|
||||
) {
|
||||
self.tracker.update_activity(handle);
|
||||
if socket.endpoint().port == 53 {
|
||||
while let Ok((data, meta)) = socket.recv() {
|
||||
// Передаем время в вызов recv для DNS-сокета
|
||||
while let Ok((data, meta)) = socket.recv(now) {
|
||||
if let Some(res) = self.resolver.process_dns_query(data) {
|
||||
let _ = socket.send_slice(&res, meta);
|
||||
}
|
||||
@@ -316,7 +328,8 @@ impl ConnectionManager {
|
||||
return;
|
||||
}
|
||||
if let Some(conn) = self.tracker.get_udp_mut(handle) {
|
||||
if !conn.tick(socket) {
|
||||
// Передаем время в tick
|
||||
if !conn.tick(socket, now) {
|
||||
self.tracker.queue_removal(handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +108,9 @@ impl Engine {
|
||||
|
||||
loop {
|
||||
let mut repeat_poll = true;
|
||||
let now = Self::current_time();
|
||||
while repeat_poll {
|
||||
self.manager.process_sockets(&mut self.socket_set);
|
||||
self.manager.process_sockets(&mut self.socket_set, now);
|
||||
let poll_res = self.poll();
|
||||
self.manager.cleanup(&mut self.socket_set);
|
||||
repeat_poll = matches!(poll_res, PollResult::SocketStateChanged);
|
||||
|
||||
Reference in New Issue
Block a user