cleanup: cfg

This commit is contained in:
dr-frmr 2024-07-08 13:33:03 +02:00
parent e7ca58c9d4
commit 22d4d8c5e2
No known key found for this signature in database
5 changed files with 31 additions and 46 deletions

View File

@ -190,13 +190,6 @@ impl State {
.get(self.package_hashes.get(package_id)?)
}
fn get_listing_with_hash_mut(
&mut self,
package_hash: &PackageHash,
) -> Option<&mut PackageListing> {
self.listed_packages.get_mut(package_hash)
}
pub fn get_downloaded_package(&self, package_id: &PackageId) -> Option<PackageState> {
self.downloaded_packages.get(package_id).cloned()
}

View File

@ -14,6 +14,7 @@ use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr},
str::FromStr,
};
wit_bindgen::generate!({
path: "target/wit",
world: "kimap-indexer-sys-v0",
@ -65,7 +66,7 @@ sol! {
call_init!(init);
fn init(our: Address) {
println!("indexing on contract address {}", KIMAP_ADDRESS);
println!("indexing on contract address {KIMAP_ADDRESS}");
// we **can** persist PKI state between boots but with current size, it's
// more robust just to reload the whole thing. the new contracts will allow
@ -83,7 +84,7 @@ fn init(our: Address) {
match main(our, state) {
Ok(_) => {}
Err(e) => {
println!("error: {:?}", e);
println!("error: {e:?}");
}
}
}
@ -130,7 +131,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
Ok(logs) => {
for log in logs {
match handle_log(&our, &mut state, &log, &eth_provider) {
Ok(_) => {}
Ok(()) => {}
Err(e) => {
println!("log-handling error! {e:?}");
}
@ -139,10 +140,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
break;
}
Err(e) => {
println!(
"got eth error while fetching logs: {:?}, trying again in 5s...",
e
);
println!("got eth error while fetching logs: {e:?}, trying again in 5s...");
std::thread::sleep(std::time::Duration::from_secs(5));
continue;
}
@ -162,7 +160,7 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
continue;
};
if source.process == "eth:distro:sys" {
if source.process() == "eth:distro:sys" {
handle_eth_message(
&our,
&mut state,
@ -179,17 +177,20 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
match request {
// IndexerRequests, especially NamehashToName, relevant anymore? if they're mostly queried from the net runtime?
IndexerRequests::NamehashToName(NamehashToNameRequest { ref hash, block }) => {
// if block <= state.block {
// Response::new()
// .body(serde_json::to_vec(&state.names.get(hash))?)
// .send()?;
// } else {
// pending_requests
// .entry(block)
// .or_insert(vec![])
// .push(request);
// }
IndexerRequests::NamehashToName(NamehashToNameRequest {
ref block,
ref hash,
}) => {
if *block <= state.block {
Response::new()
.body(serde_json::to_vec(&state.names.get(hash))?)
.send()?;
} else {
pending_requests
.entry(*block)
.or_insert(vec![])
.push(request);
}
}
IndexerRequests::NodeInfo(NodeInfoRequest { ref name, block }) => {
if block <= state.block {
@ -234,15 +235,15 @@ fn handle_eth_message(
Ok(eth::EthSub { result, .. }) => {
if let eth::SubscriptionResult::Log(log) = result {
match handle_log(our, state, &log, eth_provider) {
Ok(_) => {}
Ok(()) => {}
Err(e) => {
println!("log-handling error! {e:?}");
}
}
}
}
Err(_e) => {
println!("got eth subscription error");
Err(e) => {
println!("got eth subscription error ({e:?}), resubscribing");
subscribe_to_logs(&eth_provider, state.block - 1, filter.clone());
}
}
@ -317,10 +318,7 @@ fn handle_log(
let get_return = getCall::abi_decode_returns(&res, false)?;
let tba = get_return.tokenBoundAccount.to_string();
state.names.insert(child_hash.clone(), name.clone());
println!(
"got mint, name: {}, child_hash: {}, tba: {}",
name, child_hash, tba
);
println!("got mint, name: {name}, child_hash: {child_hash}, tba: {tba}",);
state
.nodes
.entry(name.clone())
@ -353,10 +351,7 @@ fn handle_log(
let name = get_node_name(state, &node_hash);
println!(
"got note, from name: {}, note: {}, note_hash: {}",
name, note, node_hash
);
println!("got note, from name: {name}, note: {note}, note_hash: {node_hash}",);
match note.as_str() {
"~ws-port" => {
let ws = bytes_to_port(&decoded.data);
@ -468,7 +463,7 @@ fn get_node_name(state: &mut State, parent_hash: &str) -> String {
}
/// note, unlike get_node_name, includes the label.
/// e.g label "testing" with parenthash_resolved = "parent.os" would return "testing.parent.os"
/// e.g label "testing" with parenthash_resolved = "parent.os" would return "testing.parent.os"
fn get_full_name(state: &mut State, label: &str, parent_hash: &str) -> String {
let mut current_hash = parent_hash;
let mut full_name = label.to_string();

View File

@ -197,6 +197,7 @@ pub fn bytes_to_ip(bytes: &[u8]) -> Result<IpAddr, String> {
}
}
#[cfg(feature = "simulation-mode")]
pub fn ip_to_bytes(ip: IpAddr) -> [u8; 16] {
match ip {
IpAddr::V4(ipv4) => {
@ -215,10 +216,6 @@ pub fn bytes_to_port(bytes: &[u8]) -> Result<u16, String> {
}
}
pub fn port_to_bytes(port: u16) -> [u8; 2] {
port.to_be_bytes()
}
/// randomly generated key to encrypt file chunks,
pub fn generate_file_key() -> Vec<u8> {
use ring::rand::SecureRandom;

View File

@ -15,7 +15,7 @@ use std::sync::Arc;
use tokio::sync::mpsc;
mod eth;
//#[cfg(feature = "simulation-mode")]
#[cfg(feature = "simulation-mode")]
mod fakenet;
mod http;
mod kernel;
@ -766,7 +766,6 @@ async fn login_with_password(
password: &str,
) -> (Identity, Vec<u8>, Keyfile) {
use {
alloy_primitives::Address as EthAddress,
ring::signature::KeyPair,
sha2::{Digest, Sha256},
};

View File

@ -6,8 +6,7 @@ use alloy::rpc::client::WsConnect;
use alloy::rpc::types::eth::{TransactionInput, TransactionRequest};
use alloy::signers::Signature;
use alloy_primitives::{Address as EthAddress, Bytes, FixedBytes, U256};
use alloy_sol_macro::sol;
use alloy_sol_types::{eip712_domain, SolCall, SolStruct, SolValue};
use alloy_sol_types::{eip712_domain, SolCall, SolStruct};
use base64::{engine::general_purpose::STANDARD as base64_standard, Engine};
use lib::types::core::{
BootInfo, Identity, ImportKeyfileInfo, Keyfile, KeyfileVet, KeyfileVetted, LoginAndResetInfo,
@ -27,6 +26,8 @@ use warp::{
},
Filter, Rejection, Reply,
};
#[cfg(feature = "simulation-mode")]
use {alloy_sol_macro::sol, alloy_sol_types::SolValue};
type RegistrationSender = mpsc::Sender<(Identity, Keyfile, Vec<u8>)>;