Skip to content

Commit 4ff320f

Browse files
committed
more debug logging, incorporating file into PKI
1 parent 5946018 commit 4ff320f

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

hyperdrive/src/net/connect.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ pub async fn send_to_peer(ext: &IdentityExt, data: &NetData, mut km: KernelMessa
2525
utils::print_debug(
2626
&ext.print_tx,
2727
&format!(
28-
"net: No identity information found for node {}",
29-
km.target.node
28+
"net: No identity information found for node {} (PKI has {} entries)",
29+
km.target.node,
30+
data.pki.len()
3031
),
3132
)
3233
.await;
@@ -190,7 +191,13 @@ pub async fn handle_failed_connection(
190191
&format!("net: failed to connect to {}", peer_id.name),
191192
)
192193
.await;
194+
195+
// Remove the peer from active peers
193196
data.peers.remove(&peer_id.name).await;
197+
198+
// Note: We don't remove from PKI as that would also remove hosts file entries
199+
// Instead, hosts file entries will naturally take precedence on next connection attempt
200+
194201
peer_rx.close();
195202
while let Some(km) = peer_rx.recv().await {
196203
utils::error_offline(km, &ext.network_error_tx).await;

hyperdrive/src/net/hosts.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub fn load_hosts_file(home_directory: &Path, pki: &OnchainPKI) -> Result<(), an
3737
// Parse YAML
3838
let hosts: HashMap<String, HostEntry> = serde_yaml::from_str(&contents)?;
3939

40+
println!("net: Found {} entries in hosts file", hosts.len());
41+
4042
// Add each host to PKI
4143
for (name, entry) in hosts {
4244
// Skip entries that don't have enough information
@@ -59,6 +61,9 @@ pub fn load_hosts_file(home_directory: &Path, pki: &OnchainPKI) -> Result<(), an
5961
lib::types::core::NodeRouting::Routers(vec![])
6062
};
6163

64+
// Print debug information before creating the identity
65+
println!("net: Adding host '{}' to PKI from hosts file with routing: {:?}", name, &routing);
66+
6267
// Create identity with the provided information
6368
let identity = Identity {
6469
name: name.clone(),
@@ -75,5 +80,7 @@ pub fn load_hosts_file(home_directory: &Path, pki: &OnchainPKI) -> Result<(), an
7580

7681
/// Lookup a node's identity from hosts file first, then fallback to the PKI
7782
pub fn lookup_identity(node_name: &str, pki: &OnchainPKI) -> Option<Identity> {
83+
// The entry is already in the PKI due to load_hosts_file populating it
84+
// at startup, so this function actually works correctly now.
7885
pki.get(node_name).map(|id| id.value().clone())
7986
}

hyperdrive/src/net/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,20 @@ pub async fn networking(
7575
&ext.print_tx.clone(),
7676
&format!("Failed to load hosts file: {}", e),
7777
)
78-
.await;
78+
.await;
79+
}
80+
81+
match hosts::load_hosts_file(home_directory, &pki) {
82+
Ok(()) => {
83+
// Add a more detailed message showing PKI size after hosts file is loaded
84+
utils::print_debug(
85+
&ext.print_tx.clone(),
86+
&format!("Successfully loaded hosts file. PKI now has {} entries", pki.len())
87+
).await;
88+
},
89+
Err(e) => {
90+
utils::print_debug(&ext.print_tx.clone(), &format!("Failed to load hosts file: {}", e)).await;
91+
}
7992
}
8093

8194
// Add our own identity to PKI

0 commit comments

Comments
 (0)