mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 02:09:06 +00:00
release dashmap memory (#1485)
This commit is contained in:
@@ -255,6 +255,7 @@ impl IcmpProxy {
|
||||
loop {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||
nat_table.retain(|_, v| v.start_time.elapsed().as_secs() < 20);
|
||||
nat_table.shrink_to_fit();
|
||||
}
|
||||
}
|
||||
.instrument(tracing::info_span!("icmp proxy nat table cleaner")),
|
||||
|
||||
@@ -187,6 +187,7 @@ impl IpReassembler {
|
||||
pub fn remove_expired_packets(&self) {
|
||||
let timeout = self.timeout;
|
||||
self.packets.retain(|_, v| v.timestamp.elapsed() <= timeout);
|
||||
self.packets.shrink_to_fit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -491,6 +491,9 @@ impl KcpProxyDst {
|
||||
);
|
||||
crate::defer! {
|
||||
proxy_entries.remove(&conn_id);
|
||||
if proxy_entries.capacity() - proxy_entries.len() > 16 {
|
||||
proxy_entries.shrink_to_fit();
|
||||
}
|
||||
}
|
||||
|
||||
let src_ip = src_socket.ip();
|
||||
|
||||
@@ -333,6 +333,9 @@ impl QUICProxyDst {
|
||||
let remote_addr = conn.remote_address();
|
||||
defer!(
|
||||
proxy_entries.remove(&remote_addr);
|
||||
if proxy_entries.capacity() - proxy_entries.len() > 16 {
|
||||
proxy_entries.shrink_to_fit();
|
||||
}
|
||||
);
|
||||
let ret = timeout(
|
||||
std::time::Duration::from_secs(10),
|
||||
|
||||
@@ -958,6 +958,7 @@ impl Socks5Server {
|
||||
let udp_client_map = self.udp_client_map.clone();
|
||||
let udp_forward_task = self.udp_forward_task.clone();
|
||||
let entries = self.entries.clone();
|
||||
let cancel_tokens = self.cancel_tokens.clone();
|
||||
self.tasks.lock().unwrap().spawn(async move {
|
||||
loop {
|
||||
tokio::time::sleep(Duration::from_secs(30)).await;
|
||||
@@ -972,6 +973,11 @@ impl Socks5Server {
|
||||
}
|
||||
_ => true,
|
||||
});
|
||||
|
||||
udp_client_map.shrink_to_fit();
|
||||
udp_forward_task.shrink_to_fit();
|
||||
entries.shrink_to_fit();
|
||||
cancel_tokens.shrink_to_fit();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -513,6 +513,7 @@ impl<C: NatDstConnector> TcpProxy<C> {
|
||||
true
|
||||
}
|
||||
});
|
||||
syn_map.shrink_to_fit();
|
||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||
}
|
||||
};
|
||||
@@ -706,6 +707,12 @@ impl<C: NatDstConnector> TcpProxy<C> {
|
||||
) {
|
||||
conn_map.remove(&nat_entry.id);
|
||||
addr_conn_map.remove_if(&nat_entry.src, |_, entry| entry.id == nat_entry.id);
|
||||
if conn_map.capacity() - conn_map.len() > 16 {
|
||||
conn_map.shrink_to_fit();
|
||||
}
|
||||
if addr_conn_map.capacity() - addr_conn_map.len() > 16 {
|
||||
addr_conn_map.shrink_to_fit();
|
||||
}
|
||||
}
|
||||
|
||||
async fn connect_to_nat_dst(
|
||||
|
||||
@@ -14,7 +14,7 @@ use pnet::packet::{
|
||||
udp::{self, MutableUdpPacket},
|
||||
Packet,
|
||||
};
|
||||
use tachyonix::{channel, Receiver, Sender, TrySendError};
|
||||
use tokio::sync::mpsc::{channel, error::TrySendError, Receiver, Sender};
|
||||
use tokio::{
|
||||
net::UdpSocket,
|
||||
sync::Mutex,
|
||||
@@ -144,7 +144,7 @@ impl UdpNatEntry {
|
||||
real_ipv4: Ipv4Addr,
|
||||
mapped_ipv4: Ipv4Addr,
|
||||
) {
|
||||
let (s, mut r) = tachyonix::channel(128);
|
||||
let (s, mut r) = channel(128);
|
||||
|
||||
let self_clone = self.clone();
|
||||
let recv_task = ScopedTask::from(tokio::spawn(async move {
|
||||
@@ -190,7 +190,7 @@ impl UdpNatEntry {
|
||||
let self_clone = self.clone();
|
||||
let send_task = ScopedTask::from(tokio::spawn(async move {
|
||||
let mut ip_id = 1;
|
||||
while let Ok((mut packet, len, src_socket)) = r.recv().await {
|
||||
while let Some((mut packet, len, src_socket)) = r.recv().await {
|
||||
let SocketAddr::V4(mut src_v4) = src_socket else {
|
||||
continue;
|
||||
};
|
||||
@@ -422,6 +422,7 @@ impl UdpProxy {
|
||||
true
|
||||
}
|
||||
});
|
||||
nat_table.shrink_to_fit();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -438,7 +439,7 @@ impl UdpProxy {
|
||||
let peer_manager = self.peer_manager.clone();
|
||||
let is_latency_first = self.global_ctx.get_flags().latency_first;
|
||||
self.tasks.lock().await.spawn(async move {
|
||||
while let Ok(mut msg) = receiver.recv().await {
|
||||
while let Some(mut msg) = receiver.recv().await {
|
||||
let hdr = msg.mut_peer_manager_header().unwrap();
|
||||
hdr.set_latency_first(is_latency_first);
|
||||
let to_peer_id = hdr.to_peer_id.into();
|
||||
|
||||
Reference in New Issue
Block a user