mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-07 04:59:49 +00:00
client: remove Heartbeat
This commit is contained in:
@@ -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<u8>,
|
||||
pub(super) snapshot: Option<DnsSnapshot>,
|
||||
}
|
||||
|
||||
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<Heartbeat> for HeartbeatRequest {
|
||||
fn from(value: Heartbeat) -> Self {
|
||||
Self {
|
||||
id: Some(value.id.into()),
|
||||
digest: value.digest,
|
||||
snapshot: value.snapshot.map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<HeartbeatRequest> for Heartbeat {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: HeartbeatRequest) -> Result<Self, Self::Error> {
|
||||
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<DnsPeerMgr>,
|
||||
@@ -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<TcpTunnelConnector>,
|
||||
heartbeat: &mut Heartbeat,
|
||||
heartbeat: &mut HeartbeatRequest,
|
||||
) -> anyhow::Result<()> {
|
||||
let request =
|
||||
if heartbeat.snapshot.is_none() || self.mgr.dirty.swap(false, Ordering::Release) {
|
||||
|
||||
Reference in New Issue
Block a user