rpc: add digest

This commit is contained in:
Luna Yao
2026-02-18 18:49:40 +01:00
parent ee3b7f2335
commit 83bdcf0d2b
3 changed files with 17 additions and 2 deletions
+2 -1
View File
@@ -69,6 +69,7 @@ use crate::{
},
use_global_var,
};
use crate::proto::dns::DeterministicDigest;
use super::{
graph_algo::dijkstra_with_first_hop,
@@ -260,7 +261,7 @@ impl RoutePeerInfo {
ipv6_addr: global_ctx.get_ipv6().map(|x| x.into()),
groups: global_ctx.get_acl_groups(my_peer_id),
dns: Some(global_ctx.config.get_dns().export()),
dns: global_ctx.config.get_dns().export().digest(),
noise_static_pubkey,
+14
View File
@@ -1,7 +1,21 @@
use serde::Serialize;
use sha2::{Digest, Sha256};
use std::fmt::Display;
include!(concat!(env!("OUT_DIR"), "/dns.rs"));
pub trait DeterministicDigest: Serialize {
fn digest(&self) -> Vec<u8> {
let json = serde_json::to_vec(self).expect("failed to serialize the object to json");
let mut hasher = Sha256::new();
hasher.update(json);
hasher.finalize().to_vec()
}
}
impl DeterministicDigest for DnsConfigPb {}
impl DeterministicDigest for ZoneConfigPb {}
impl Display for ZoneConfigPb {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "; EasyTier Magic DNS zone file")?;
+1 -1
View File
@@ -48,7 +48,7 @@ message RoutePeerInfo {
// Trusted credential public keys published by admin nodes (holding network_secret)
repeated TrustedCredentialPubkeyProof trusted_credential_pubkeys = 19;
dns.DnsConfigPb dns = 20;
bytes dns = 20;
}
message PeerIdVersion {