FIX: correctly allow indirect node to boot that's been updated onchain to be indirect after having been booted as direct in the past. also fix search in terminal.

This commit is contained in:
dr-frmr 2024-06-14 01:44:13 -04:00
parent ac49747a52
commit 7c00996b78
No known key found for this signature in database
4 changed files with 37 additions and 19 deletions

View File

@ -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)
}

View File

@ -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) = <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,
@ -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(())
}

View File

@ -386,9 +386,6 @@ pub async fn terminal(
}
search_mode = true;
let search_query = &current_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(&current_line, prompt_len, win_cols, (line_col, cursor_col))),
Print(utils::truncate_in_place(
&format!("{} * {}", our.name, &current_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(&current_line, prompt_len, win_cols, (line_col, cursor_col))),
Print(utils::truncate_in_place(
&format!("{} > {}", our.name, &current_line[prompt_len..]),
prompt_len,
win_cols,
(line_col, cursor_col))),
cursor::MoveTo(cursor_col, win_rows),
)?;
},

View File

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