Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions kinode/src/net/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 3 additions & 16 deletions kinode/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
};

Expand Down Expand Up @@ -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 => (
Expand All @@ -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!(
Expand Down
3 changes: 1 addition & 2 deletions kinode/src/net/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -98,6 +98,5 @@ pub struct IdentityExt {
pub struct NetData {
pub pki: OnchainPKI,
pub peers: Peers,
pub names: PKINames,
pub pending_passthroughs: PendingPassthroughs,
}
7 changes: 3 additions & 4 deletions kinode/src/net/utils.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions lib/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down