diff --git a/easytier/src/dns/client.rs b/easytier/src/dns/client.rs index a19efae9..448ed8c8 100644 --- a/easytier/src/dns/client.rs +++ b/easytier/src/dns/client.rs @@ -1,65 +1,17 @@ use super::config::DNS_SERVER_RPC_ADDR; -use crate::dns::peer_mgr::{DnsPeerMgr, DnsSnapshot}; +use crate::dns::peer_mgr::DnsPeerMgr; use crate::peers::peer_manager::PeerManager; use crate::proto::dns::{DnsPeerManagerRpcServer, DnsServerRpcClientFactory, HeartbeatRequest}; use crate::proto::peer_rpc::RoutePeerInfo; use crate::proto::rpc_impl::standalone::StandAloneClient; use crate::proto::rpc_types::controller::BaseController; use crate::tunnel::tcp::TcpTunnelConnector; -use crate::utils::DeterministicDigest; use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; use tokio::task::JoinSet; use uuid::Uuid; -#[derive(Debug, Clone, Default)] -pub struct Heartbeat { - pub(super) id: Uuid, - pub(super) digest: Vec, - pub(super) snapshot: Option, -} - -impl Heartbeat { - pub fn new(id: Uuid) -> Self { - Self { - id, - - ..Default::default() - } - } - - pub fn update(&mut self, snapshot: DnsSnapshot) { - self.digest = snapshot.digest(); - self.snapshot = Some(snapshot); - } -} - -impl From for HeartbeatRequest { - fn from(value: Heartbeat) -> Self { - Self { - id: Some(value.id.into()), - digest: value.digest, - snapshot: value.snapshot.map(Into::into), - } - } -} - -impl TryFrom for Heartbeat { - type Error = anyhow::Error; - - fn try_from(value: HeartbeatRequest) -> Result { - Ok(Self { - id: value - .id - .ok_or(anyhow::anyhow!("missing id in heartbeat"))? - .into(), - digest: value.digest, - snapshot: value.snapshot.map(TryInto::try_into).transpose()?, - }) - } -} - #[derive(Debug)] pub struct DnsClient { mgr: Arc, @@ -91,7 +43,11 @@ impl DnsClient { pub async fn run(&self) { let mut rpc = StandAloneClient::new(TcpTunnelConnector::new(DNS_SERVER_RPC_ADDR.clone())); - let mut heartbeat = Heartbeat::new(self.id()); + let mut heartbeat = HeartbeatRequest { + id: Some(self.id().into()), + + ..Default::default() + }; loop { if let Err(e) = self.heartbeat(&mut rpc, &mut heartbeat).await { tracing::error!("DnsClient heartbeat failed: {:?}", e); @@ -103,7 +59,7 @@ impl DnsClient { async fn heartbeat( &self, rpc: &mut StandAloneClient, - heartbeat: &mut Heartbeat, + heartbeat: &mut HeartbeatRequest, ) -> anyhow::Result<()> { let request = if heartbeat.snapshot.is_none() || self.mgr.dirty.swap(false, Ordering::Release) {