nit fixes

This commit is contained in:
dr-frmr 2024-07-08 19:18:03 +02:00
parent 0bb97b61da
commit 352e1f1059
No known key found for this signature in database
4 changed files with 20 additions and 48 deletions

View File

@ -161,26 +161,6 @@ pub fn namehash(name: &str) -> [u8; 32] {
node.into()
}
// pub fn namehash(name: &str) -> [u8; 32] {
// let mut node = [0u8; 32];
// if name.is_empty() {
// return node;
// }
// let mut labels: Vec<&str> = name.split('.').collect();
// labels.reverse();
// for label in labels.iter() {
// let mut hasher = Keccak256::new();
// hasher.update(label.as_bytes());
// let labelhash = hasher.finalize();
// hasher = Keccak256::new();
// hasher.update(&node);
// hasher.update(labelhash);
// node = hasher.finalize().into();
// }
// node
// }
pub fn bytes_to_ip(bytes: &[u8]) -> Result<IpAddr, String> {
match bytes.len() {
16 => {
@ -193,7 +173,7 @@ pub fn bytes_to_ip(bytes: &[u8]) -> Result<IpAddr, String> {
Ok(IpAddr::V6(Ipv6Addr::from(ip_num)))
}
}
_ => Err("Invalid byte length for IP address".to_string()),
other => Err(format!("Invalid byte length for IP address: {other}")),
}
}
@ -212,7 +192,7 @@ pub fn ip_to_bytes(ip: IpAddr) -> [u8; 16] {
pub fn bytes_to_port(bytes: &[u8]) -> Result<u16, String> {
match bytes.len() {
2 => Ok(u16::from_be_bytes([bytes[0], bytes[1]])),
_ => Err("Invalid byte length for port".to_string()),
other => Err(format!("Invalid byte length for port: {other}")),
}
}

View File

@ -409,10 +409,8 @@ async fn main() {
let quit_msg: String = tokio::select! {
Some(Ok(res)) = tasks.join_next() => {
match res {
Ok(_) => "graceful exit".into(),
Err(e) => format!(
"runtime crash: {e:?}"
),
Ok(()) => "graceful exit".into(),
Err(e) => format!("runtime crash: {e:?}"),
}
}
@ -462,10 +460,9 @@ async fn set_http_server_port(set_port: Option<&u16>) -> u16 {
match http::utils::find_open_port(*port, port + 1).await {
Some(bound) => bound.local_addr().unwrap().port(),
None => {
println!(
"error: couldn't bind {}; first available port found was {}. \
panic!(
"error: couldn't bind {port}; first available port found was {}. \
Set an available port with `--port` and try again.",
port,
http::utils::find_open_port(*port, port + 1000)
.await
.expect("no ports found in range")
@ -473,7 +470,6 @@ async fn set_http_server_port(set_port: Option<&u16>) -> u16 {
.unwrap()
.port(),
);
panic!();
}
}
} else {
@ -538,7 +534,7 @@ pub async fn simulate_node(
panic!("Fake node must be booted with either a --fake-node-name, --password, or both.");
}
Some(password) => {
let keyfile = tokio::fs::read(format!("{}/.keys", home_directory_path))
let keyfile = tokio::fs::read(format!("{home_directory_path}/.keys"))
.await
.expect("could not read keyfile");
let decoded = keygen::decode_keyfile(&keyfile, &password)
@ -608,7 +604,7 @@ pub async fn simulate_node(
);
tokio::fs::write(
format!("{}/.keys", home_directory_path),
format!("{home_directory_path}/.keys"),
encoded_keyfile.clone(),
)
.await
@ -621,9 +617,9 @@ pub async fn simulate_node(
async fn create_home_directory(home_directory_path: &str) {
if let Err(e) = tokio::fs::create_dir_all(home_directory_path).await {
panic!("failed to create home directory: {:?}", e);
panic!("failed to create home directory: {e:?}");
}
println!("home at {}\r", home_directory_path);
println!("home at {home_directory_path}\r");
}
/// build the command line interface for kinode
@ -689,7 +685,7 @@ async fn find_public_ip() -> std::net::Ipv4Addr {
println!("Finding public IP address...");
match tokio::time::timeout(std::time::Duration::from_secs(5), public_ip::addr_v4()).await {
Ok(Some(ip)) => {
println!("Public IP found: {}", ip);
println!("Public IP found: {ip}");
ip
}
_ => {
@ -744,7 +740,7 @@ async fn serve_register_fe(
}
};
tokio::fs::write(format!("{}/.keys", home_directory_path), &encoded_keyfile)
tokio::fs::write(format!("{home_directory_path}/.keys"), &encoded_keyfile)
.await
.unwrap();
@ -812,7 +808,7 @@ 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)
tokio::fs::write(format!("{home_directory_path}/.keys"), &disk_keyfile)
.await
.unwrap();

View File

@ -691,22 +691,15 @@ pub async fn assign_routing(
};
let netkey = getCall::abi_decode_returns(&results.returnData[0], false)?;
let net_key = netkey.data;
let ws = getCall::abi_decode_returns(&results.returnData[1], false)?;
let ws_data = ws.data;
let tcp = getCall::abi_decode_returns(&results.returnData[2], false)?;
let tcp_data = tcp.data;
let ip = getCall::abi_decode_returns(&results.returnData[3], false)?;
let ip_data = ip.data;
let ip = keygen::bytes_to_ip(&ip_data);
let ws = keygen::bytes_to_port(&ws_data);
let tcp = keygen::bytes_to_port(&tcp_data);
let ip = keygen::bytes_to_ip(&ip.data);
let ws = keygen::bytes_to_port(&ws.data);
let tcp = keygen::bytes_to_port(&tcp.data);
if net_key.to_string() != our.networking_key {
if netkey.data.to_string() != our.networking_key {
return Err(anyhow::anyhow!(
"Networking key from PKI does not match our saved networking key"
));
@ -744,6 +737,7 @@ pub async fn assign_routing(
}
Ok(())
}
async fn success_response(
sender: Arc<RegistrationSender>,
our: Identity,

View File

@ -39,6 +39,8 @@ sol! {
uint8 operation
) external payable returns (bytes memory returnData);
/// The data structure signed by user to bootstrap the node.
/// Never posted onchain or across network.
struct Boot {
string username;
bytes32 password_hash;