Merge pull request #445 from kinode-dao/dr/remove-namehashes-from-net

net: remove all namehash usage
This commit is contained in:
bitful-pannul 2024-07-15 19:07:13 +02:00 committed by GitHub
commit 5427b6a213
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 8 additions and 31 deletions

View File

@ -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;

View File

@ -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!(

View File

@ -55,8 +55,8 @@ pub struct RoutingRequest {
}
pub type Peers = Arc<DashMap<String, Peer>>;
pub type PKINames = Arc<DashMap<String, NodeId>>;
pub type OnchainPKI = Arc<DashMap<String, Identity>>;
/// (from, target) -> from's socket
pub type PendingPassthroughs = Arc<DashMap<(NodeId, NodeId), PendingStream>>;
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,
}

View File

@ -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 {

View File

@ -2005,14 +2005,10 @@ pub enum NetAction {
/// in the future could get from remote provider
KnsUpdate(KnsUpdate),
KnsBatchUpdate(Vec<KnsUpdate>),
/// 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.