mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-03 09:35:41 +00:00
server: cleanup resources in run and drop
This commit is contained in:
+20
-12
@@ -5,8 +5,10 @@ use crate::peer_center::instance::PeerCenterPeerManagerTrait;
|
|||||||
use crate::peers::peer_manager::PeerManager;
|
use crate::peers::peer_manager::PeerManager;
|
||||||
use crate::peers::NicPacketFilter;
|
use crate::peers::NicPacketFilter;
|
||||||
use crate::proto::dns::DnsNodeMgrRpcServer;
|
use crate::proto::dns::DnsNodeMgrRpcServer;
|
||||||
|
use crate::proto::rpc_impl::standalone::StandAloneServer;
|
||||||
use crate::tunnel::common::bind_socket;
|
use crate::tunnel::common::bind_socket;
|
||||||
use crate::tunnel::packet_def::ZCPacket;
|
use crate::tunnel::packet_def::ZCPacket;
|
||||||
|
use crate::tunnel::tcp::TcpTunnelListener;
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use derive_more::{Deref, DerefMut, From, Into};
|
use derive_more::{Deref, DerefMut, From, Into};
|
||||||
use hickory_proto::rr::Record;
|
use hickory_proto::rr::Record;
|
||||||
@@ -26,8 +28,8 @@ use pnet::packet::ipv4::{Ipv4Packet, MutableIpv4Packet};
|
|||||||
use pnet::packet::udp::{MutableUdpPacket, UdpPacket};
|
use pnet::packet::udp::{MutableUdpPacket, UdpPacket};
|
||||||
use pnet::packet::{icmp, ipv4, udp, MutablePacket, Packet};
|
use pnet::packet::{icmp, ipv4, udp, MutablePacket, Packet};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::io;
|
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||||
|
use std::{io, iter};
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
use tokio::{sync::RwLock, task::JoinHandle};
|
use tokio::{sync::RwLock, task::JoinHandle};
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
@@ -89,7 +91,6 @@ impl DnsServerRuntime {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for DnsServerRuntime {
|
impl Drop for DnsServerRuntime {
|
||||||
@@ -163,16 +164,11 @@ pub struct DnsServer {
|
|||||||
const DNS_SERVER_LISTENER_TCP_TIMEOUT: Duration = Duration::from_secs(5);
|
const DNS_SERVER_LISTENER_TCP_TIMEOUT: Duration = Duration::from_secs(5);
|
||||||
|
|
||||||
impl DnsServer {
|
impl DnsServer {
|
||||||
pub fn new(peer_mgr: Arc<PeerManager>) -> Self {
|
pub fn new(peer_mgr: Arc<PeerManager>, rpc: StandAloneServer<TcpTunnelListener>) -> Self {
|
||||||
let mgr = Arc::new(DnsNodeMgr::new());
|
let mgr = Arc::new(DnsNodeMgr::new());
|
||||||
peer_mgr
|
|
||||||
.get_peer_rpc_mgr()
|
rpc.registry()
|
||||||
.rpc_server()
|
.register(DnsNodeMgrRpcServer::new_arc(mgr.clone()), "");
|
||||||
.registry()
|
|
||||||
.register(
|
|
||||||
DnsNodeMgrRpcServer::new_arc(mgr.clone()),
|
|
||||||
&peer_mgr.get_global_ctx_ref().get_network_name(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
mgr,
|
mgr,
|
||||||
@@ -227,6 +223,7 @@ impl DnsServer {
|
|||||||
|
|
||||||
pub async fn run(&self) {
|
pub async fn run(&self) {
|
||||||
let dirty = &self.mgr.dirty;
|
let dirty = &self.mgr.dirty;
|
||||||
|
let mut runtime = None;
|
||||||
|
|
||||||
tokio::join!(
|
tokio::join!(
|
||||||
async {
|
async {
|
||||||
@@ -248,7 +245,6 @@ impl DnsServer {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async {
|
async {
|
||||||
let mut runtime = None;
|
|
||||||
loop {
|
loop {
|
||||||
dirty.listeners.notified().await;
|
dirty.listeners.notified().await;
|
||||||
if dirty.listeners.reset() {
|
if dirty.listeners.reset() {
|
||||||
@@ -264,6 +260,18 @@ impl DnsServer {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
self.reload_addresses(iter::empty()).await;
|
||||||
|
if let Some(runtime) = runtime.take() {
|
||||||
|
let _ = runtime.stop().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for DnsServer {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
tracing::info!("DnsServer is dropped");
|
||||||
|
// TODO: remove addresses
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user