From 6fe711a06778d47b30cc4b6d9f56e18f6818ecb4 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Mon, 15 Jul 2024 19:02:21 +0200 Subject: [PATCH] net: remove all namehash usage! --- kinode/src/net/connect.rs | 6 +----- kinode/src/net/mod.rs | 19 +++---------------- kinode/src/net/types.rs | 3 +-- kinode/src/net/utils.rs | 7 +++---- lib/src/core.rs | 4 ---- 5 files changed, 8 insertions(+), 31 deletions(-) diff --git a/kinode/src/net/connect.rs b/kinode/src/net/connect.rs index d6f82fb8..9b8b8554 100644 --- a/kinode/src/net/connect.rs +++ b/kinode/src/net/connect.rs @@ -101,11 +101,7 @@ async fn connect_via_router( routers.shuffle(&mut rand::thread_rng()); routers }; - for router_namehash in &routers_shuffled { - let Some(router_name) = data.names.get(router_namehash) else { - // router does not exist in PKI that we know of - continue; - }; + for router_name in &routers_shuffled { if router_name.as_ref() == ext.our.name { // we can't route through ourselves continue; diff --git a/kinode/src/net/mod.rs b/kinode/src/net/mod.rs index 01e87a34..0433bd5f 100644 --- a/kinode/src/net/mod.rs +++ b/kinode/src/net/mod.rs @@ -3,8 +3,7 @@ use lib::types::core::{ NetworkErrorSender, NodeRouting, PrintSender, }; use types::{ - IdentityExt, NetData, OnchainPKI, PKINames, Peers, PendingPassthroughs, TCP_PROTOCOL, - WS_PROTOCOL, + IdentityExt, NetData, OnchainPKI, Peers, PendingPassthroughs, TCP_PROTOCOL, WS_PROTOCOL, }; use {dashmap::DashMap, ring::signature::Ed25519KeyPair, std::sync::Arc, tokio::task::JoinSet}; @@ -47,17 +46,12 @@ pub async fn networking( // and store a mapping of peers we have an active route for let pki: OnchainPKI = Arc::new(DashMap::new()); let peers: Peers = Arc::new(DashMap::new()); - // keep a mapping of namehashes (used onchain) to node-ids. - // this allows us to act as a translator for others, and translate - // our own router namehashes if we are indirect. - let names: PKINames = Arc::new(DashMap::new()); // only used by routers let pending_passthroughs: PendingPassthroughs = Arc::new(DashMap::new()); let net_data = NetData { pki, peers, - names, pending_passthroughs, }; @@ -165,16 +159,13 @@ async fn handle_local_request( // we shouldn't get these locally, ignore } Ok(NetAction::KnsUpdate(log)) => { - utils::ingest_log(log, &data.pki, &data.names); + utils::ingest_log(log, &data.pki); } Ok(NetAction::KnsBatchUpdate(logs)) => { for log in logs { - utils::ingest_log(log, &data.pki, &data.names); + utils::ingest_log(log, &data.pki); } } - Ok(NetAction::AddName(hash, name)) => { - data.names.insert(hash, name); - } Ok(gets) => { let (response_body, response_blob) = match gets { NetAction::GetPeers => ( @@ -190,10 +181,6 @@ async fn handle_local_request( NetResponse::Peer(data.pki.get(&peer).map(|p| p.clone())), None, ), - NetAction::GetName(namehash) => ( - NetResponse::Name(data.names.get(&namehash).map(|n| n.clone())), - None, - ), NetAction::GetDiagnostics => { let mut printout = String::new(); printout.push_str(&format!( diff --git a/kinode/src/net/types.rs b/kinode/src/net/types.rs index 28aed56c..08a5cbd3 100644 --- a/kinode/src/net/types.rs +++ b/kinode/src/net/types.rs @@ -55,8 +55,8 @@ pub struct RoutingRequest { } pub type Peers = Arc>; -pub type PKINames = Arc>; pub type OnchainPKI = Arc>; + /// (from, target) -> from's socket pub type PendingPassthroughs = Arc>; pub enum PendingStream { @@ -98,6 +98,5 @@ pub struct IdentityExt { pub struct NetData { pub pki: OnchainPKI, pub peers: Peers, - pub names: PKINames, pub pending_passthroughs: PendingPassthroughs, } diff --git a/kinode/src/net/utils.rs b/kinode/src/net/utils.rs index e997641f..5a7c595c 100644 --- a/kinode/src/net/utils.rs +++ b/kinode/src/net/utils.rs @@ -1,6 +1,6 @@ use crate::net::types::{ - HandshakePayload, OnchainPKI, PKINames, Peers, PendingPassthroughs, PendingStream, - RoutingRequest, TCP_PROTOCOL, WS_PROTOCOL, + HandshakePayload, OnchainPKI, Peers, PendingPassthroughs, PendingStream, RoutingRequest, + TCP_PROTOCOL, WS_PROTOCOL, }; use lib::types::core::{ Identity, KernelMessage, KnsUpdate, Message, MessageSender, NetAction, NetworkErrorSender, @@ -175,7 +175,7 @@ pub async fn maintain_passthrough(socket_1: PendingStream, socket_2: PendingStre } } -pub fn ingest_log(log: KnsUpdate, pki: &OnchainPKI, names: &PKINames) { +pub fn ingest_log(log: KnsUpdate, pki: &OnchainPKI) { pki.insert( log.name.clone(), Identity { @@ -191,7 +191,6 @@ pub fn ingest_log(log: KnsUpdate, pki: &OnchainPKI, names: &PKINames) { }, }, ); - names.insert(log.node, log.name); } pub fn validate_signature(from: &str, signature: &[u8], message: &[u8], pki: &OnchainPKI) -> bool { diff --git a/lib/src/core.rs b/lib/src/core.rs index 24a43bef..24bdde43 100644 --- a/lib/src/core.rs +++ b/lib/src/core.rs @@ -2005,14 +2005,10 @@ pub enum NetAction { /// in the future could get from remote provider KnsUpdate(KnsUpdate), KnsBatchUpdate(Vec), - /// add a (namehash -> name) to our representation of the PKI - AddName(String, String), /// get a list of peers we are connected to GetPeers, /// get the [`Identity`] struct for a single peer GetPeer(String), - /// get the [`NodeId`] associated with a given namehash, if any - GetName(String), /// get a user-readable diagnostics string containing networking inforamtion GetDiagnostics, /// sign the attached blob payload, sign with our node's networking key.