diff --git a/kinode/src/main.rs b/kinode/src/main.rs index 204e4baa..ac4a4b67 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -746,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); @@ -822,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) } diff --git a/kinode/src/register.rs b/kinode/src/register.rs index 863a0299..db512a6e 100644 --- a/kinode/src/register.rs +++ b/kinode/src/register.rs @@ -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 @@ -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) @@ -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) = >>::abi_decode(&routers, false) else { + return Err(anyhow::anyhow!("Failed to decode node routers from PKI")); + }; + let node_ip = format!( "{}.{}.{}.{}", (ip >> 24) & 0xFF, @@ -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(); @@ -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(()) } diff --git a/kinode/src/terminal/mod.rs b/kinode/src/terminal/mod.rs index 6322a8b1..68aeadc4 100644 --- a/kinode/src/terminal/mod.rs +++ b/kinode/src/terminal/mod.rs @@ -386,9 +386,6 @@ pub async fn terminal( } search_mode = true; let search_query = ¤t_line[prompt_len..]; - if search_query.is_empty() { - continue; - } if let Some(result) = command_history.search(search_query, search_depth) { let result_underlined = utils::underline(result, search_query); execute!( @@ -407,7 +404,11 @@ pub async fn terminal( stdout, cursor::MoveTo(0, win_rows), terminal::Clear(ClearType::CurrentLine), - Print(utils::truncate_in_place(¤t_line, prompt_len, win_cols, (line_col, cursor_col))), + Print(utils::truncate_in_place( + &format!("{} * {}", our.name, ¤t_line[prompt_len..]), + prompt_len, + win_cols, + (line_col, cursor_col))), cursor::MoveTo(cursor_col, win_rows), )?; } @@ -427,7 +428,11 @@ pub async fn terminal( stdout, cursor::MoveTo(0, win_rows), terminal::Clear(ClearType::CurrentLine), - Print(utils::truncate_in_place(¤t_line, prompt_len, win_cols, (line_col, cursor_col))), + Print(utils::truncate_in_place( + &format!("{} > {}", our.name, ¤t_line[prompt_len..]), + prompt_len, + win_cols, + (line_col, cursor_col))), cursor::MoveTo(cursor_col, win_rows), )?; }, diff --git a/kinode/src/terminal/utils.rs b/kinode/src/terminal/utils.rs index ba86ee2c..9b4de7b8 100644 --- a/kinode/src/terminal/utils.rs +++ b/kinode/src/terminal/utils.rs @@ -201,6 +201,9 @@ impl CommandHistory { /// yes this is O(n) to provide desired ordering, can revisit if slow pub fn search(&mut self, find: &str, depth: usize) -> Option<&str> { let mut skips = 0; + if find.is_empty() { + return None; + } // if there is at least one match, and we've skipped past it, return oldest match let mut last_match: Option<&str> = None; for line in self.lines.iter() {