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
24 changes: 19 additions & 5 deletions kinode/src/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,9 @@ pub async fn kernel(
let mut process_handles: ProcessHandles = HashMap::new();

let mut is_debug: bool = false;
// this flag starts as true, and terminal will alert us if we can
// skip sending prints for every event.
let mut print_full_event_loop: bool = true;
let mut reboot_processes: Vec<(t::ProcessId, StartProcessMetadata, Vec<u8>)> = vec![];

// filter out OnExit::None processes from process_map
Expand Down Expand Up @@ -870,9 +873,17 @@ pub async fn kernel(
loop {
tokio::select! {
// debug mode toggle: when on, this loop becomes a manual step-through
debug = recv_debug_in_loop.recv() => {
if let Some(t::DebugCommand::Toggle) = debug {
is_debug = !is_debug;
Some(debug_command) = recv_debug_in_loop.recv() => {
match debug_command {
t::DebugCommand::ToggleStepthrough => {
is_debug = !is_debug;
},
t::DebugCommand::Step => {
// can't step here, must be in stepthrough-mode
},
t::DebugCommand::ToggleEventLoop => {
print_full_event_loop = !print_full_event_loop;
}
}
},
// network error message receiver: handle `timeout` and `offline` errors
Expand Down Expand Up @@ -1042,17 +1053,20 @@ pub async fn kernel(
while is_debug {
let debug = recv_debug_in_loop.recv().await.expect("event loop: debug channel died");
match debug {
t::DebugCommand::Toggle => is_debug = !is_debug,
t::DebugCommand::ToggleStepthrough => is_debug = !is_debug,
t::DebugCommand::Step => break,
t::DebugCommand::ToggleEventLoop => print_full_event_loop = !print_full_event_loop,
}
}
// display every single event when verbose
let _ = send_to_terminal.send(
if print_full_event_loop {
let _ = send_to_terminal.send(
t::Printout {
verbosity: 3,
content: format!("{kernel_message}")
}
).await;
}

if our.name != kernel_message.target.node {
send_to_net.send(kernel_message).await.expect("fatal: net module died");
Expand Down
31 changes: 8 additions & 23 deletions kinode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,8 @@ async fn main() {

// abort all remaining tasks
tasks.shutdown().await;
let stdout = std::io::stdout();
let mut stdout = stdout.lock();
crossterm::execute!(
stdout,
crossterm::event::DisableBracketedPaste,
crossterm::terminal::SetTitle(""),
crossterm::style::SetForegroundColor(crossterm::style::Color::Red),
crossterm::style::Print(format!("\r\n{quit_msg}\r\n")),
crossterm::style::ResetColor,
)
.expect("failed to clean up terminal visual state! your terminal window might be funky now");
// reset all modified aspects of terminal -- clean ourselves up
terminal::utils::cleanup(&quit_msg);
}

async fn set_http_server_port(set_port: Option<&u16>) -> u16 {
Expand Down Expand Up @@ -755,12 +746,9 @@ async fn serve_register_fe(
}
};

tokio::fs::write(
format!("{}/.keys", home_directory_path),
encoded_keyfile.clone(),
)
.await
.unwrap();
tokio::fs::write(format!("{}/.keys", home_directory_path), &encoded_keyfile)
.await
.unwrap();

let _ = kill_tx.send(true);

Expand Down Expand Up @@ -831,12 +819,9 @@ async fn login_with_password(
.await
.expect("information used to boot does not match information onchain");

tokio::fs::write(
format!("{}/.keys", home_directory_path),
disk_keyfile.clone(),
)
.await
.unwrap();
tokio::fs::write(format!("{}/.keys", home_directory_path), &disk_keyfile)
.await
.unwrap();

(our, disk_keyfile, k)
}
20 changes: 18 additions & 2 deletions kinode/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sol! {
function key(bytes32) external view returns (bytes32);
function nodes(bytes32) external view returns (address, uint96);
function ip(bytes32) external view returns (uint128, uint16, uint16, uint16, uint16);
function routers(bytes32) external view returns (bytes32[]);
}

/// Serve the registration page and receive POSTs and PUTs from it
Expand Down Expand Up @@ -702,6 +703,7 @@ pub async fn assign_routing(
let namehash = FixedBytes::<32>::from_slice(&keygen::namehash(&our.name));
let ip_call = ipCall { _0: namehash }.abi_encode();
let key_call = keyCall { _0: namehash }.abi_encode();
let router_call = routersCall { _0: namehash }.abi_encode();
let tx_input = TransactionInput::new(Bytes::from(ip_call));
let tx = TransactionRequest::default()
.to(kns_address)
Expand Down Expand Up @@ -731,6 +733,18 @@ pub async fn assign_routing(
));
}

let router_tx_input = TransactionInput::new(Bytes::from(router_call));
let router_tx = TransactionRequest::default()
.to(kns_address)
.input(router_tx_input);

let Ok(routers) = provider.call(&router_tx).await else {
return Err(anyhow::anyhow!("Failed to fetch node routers from PKI"));
};
let Ok(routers) = <Vec<FixedBytes<32>>>::abi_decode(&routers, false) else {
return Err(anyhow::anyhow!("Failed to decode node routers from PKI"));
};

let node_ip = format!(
"{}.{}.{}.{}",
(ip >> 24) & 0xFF,
Expand All @@ -739,6 +753,10 @@ pub async fn assign_routing(
ip & 0xFF
);

if !routers.is_empty() {
// indirect node
return Ok(());
}
if node_ip != *"0.0.0.0" && (ws != 0 || tcp != 0) {
// direct node
let mut ports = std::collections::BTreeMap::new();
Expand All @@ -763,8 +781,6 @@ pub async fn assign_routing(
ports.insert("tcp".to_string(), tcp);
}
our.routing = NodeRouting::Direct { ip: node_ip, ports };
} else {
// indirect node
}
Ok(())
}
Expand Down
Loading