From 64f5f1027ba90566cd7e31a8cceeecd56d0a9cea Mon Sep 17 00:00:00 2001 From: Revertron Date: Sun, 2 May 2021 16:02:14 +0200 Subject: [PATCH] Removed all external zones. --- build.rs | 68 ---------------------------------------- src/commons/constants.rs | 2 +- src/context.rs | 4 +-- src/lib.rs | 2 -- src/p2p/network.rs | 6 ---- src/web_ui.rs | 6 ++-- src/webview/index.html | 2 +- src/webview/scripts.js | 7 ++--- src/x_zones.rs | 41 ------------------------ 9 files changed, 9 insertions(+), 129 deletions(-) delete mode 100644 src/x_zones.rs diff --git a/build.rs b/build.rs index eb36cb7..cfd3ce8 100644 --- a/build.rs +++ b/build.rs @@ -1,77 +1,9 @@ extern crate winres; -use std::fs::File; -use std::fs::read_to_string; -use std::path::Path; -use std::io::Write; - -use crypto::digest::Digest; -use crypto::sha2::Sha256; - -const IANA_FILE: &'static str = "iana-tlds.txt"; -const IANA_HASHES: &'static str = "iana-hashes.txt"; -const IANA_ZONES_URL: &'static str = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"; - fn main() { if cfg!(target_os = "windows") { let mut res = winres::WindowsResource::new(); res.set_icon("img/logo/alfis.ico"); res.compile().unwrap(); } - - download_iana_zones(IANA_FILE, IANA_HASHES); -} - -fn download_iana_zones(zones_name: &str, hashes_name: &str) { - let response = match read_to_string(Path::new(IANA_FILE)) { - Ok(string) => { string } - Err(_) => { - let response = minreq::get(IANA_ZONES_URL).send().expect("Could not make request!"); - response.as_str().expect("Response is not a valid UTF-8!").to_lowercase() - } - }; - - let list: Vec<_> = response.split("\n").collect(); - let mut zones = String::new(); - let mut hashes = String::new(); - for string in list { - if !string.starts_with("#") && !string.is_empty() { - zones.push_str(string); - zones.push('\n'); - - hashes.push_str(&hash_identity(string)); - hashes.push('\n'); - } - } - - match File::create(Path::new(zones_name)) { - Ok(mut file) => { - file.write_all(zones.trim().as_bytes()).expect("Error saving TLDs file!"); - } - Err(e) => { panic!("Error opening TLDs file!\n{}", e); } - } - - match File::create(Path::new(hashes_name)) { - Ok(mut file) => { - file.write_all(hashes.trim().as_bytes()).expect("Error saving TLD-hashes file!"); - } - Err(e) => { panic!("Error opening TLD-hashes file!\n{}", e); } - } -} - -fn hash_identity(identity: &str) -> String { - let mut buf: [u8; 32] = [0; 32]; - let mut digest = Sha256::new(); - digest.input_str(identity); - digest.result(&mut buf); - to_hex(&buf) -} - -/// Convert bytes array to HEX format -pub fn to_hex(buf: &[u8]) -> String { - let mut result = String::new(); - for x in buf.iter() { - result.push_str(&format!("{:01$X}", x, 2)); - } - result } \ No newline at end of file diff --git a/src/commons/constants.rs b/src/commons/constants.rs index 60e4e94..ba896e7 100644 --- a/src/commons/constants.rs +++ b/src/commons/constants.rs @@ -3,7 +3,7 @@ use std::time::Duration; pub const DB_VERSION: u32 = 0; pub const CHAIN_VERSION: u32 = 1; -pub const ORIGIN_DIFFICULTY: u32 = 30; +pub const ORIGIN_DIFFICULTY: u32 = 28; pub const DOMAIN_DIFFICULTY: u32 = 24; pub const SIGNER_DIFFICULTY: u32 = 16; pub const KEYSTORE_DIFFICULTY: u32 = 23; diff --git a/src/context.rs b/src/context.rs index 3ac1f63..68128e5 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,4 +1,4 @@ -use crate::{Chain, Bus, Keystore, Settings, ExternalZones}; +use crate::{Chain, Bus, Keystore, Settings}; use crate::event::Event; #[allow(unused_imports)] use log::{trace, debug, info, warn, error}; @@ -9,7 +9,6 @@ pub struct Context { pub settings: Settings, pub keystore: Option, pub chain: Chain, - pub x_zones: ExternalZones, pub bus: Bus, pub miner_state: MinerState, } @@ -22,7 +21,6 @@ impl Context { settings, keystore, chain, - x_zones: ExternalZones::new(), bus: Bus::new(), miner_state: MinerState { mining: false, full: false } } diff --git a/src/lib.rs b/src/lib.rs index 992733f..cc41e12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,6 @@ pub use crate::p2p::Network; pub use crate::settings::Settings; pub use crate::bytes::Bytes; pub use crate::keys::Keystore; -pub use crate::x_zones::ExternalZones; pub use crate::simplebus::*; pub use crate::commons::*; @@ -24,6 +23,5 @@ pub mod dns; pub mod dns_utils; pub mod settings; pub mod bytes; -pub mod x_zones; pub mod crypto; diff --git a/src/p2p/network.rs b/src/p2p/network.rs index 6195b27..2ef0959 100644 --- a/src/p2p/network.rs +++ b/src/p2p/network.rs @@ -527,12 +527,6 @@ fn handle_block(context: Arc>, peers: &mut Peers, token: &Token, let peers_count = peers.get_peers_active_count(); let peer = peers.get_mut_peer(token).unwrap(); peer.set_received_block(block.index); - if let Some(transaction) = &block.transaction { - if context.lock().unwrap().x_zones.has_hash(&transaction.identity.to_string()) { - // This peer has mined some of the forbidden zones - return State::Banned; - } - } let mut context = context.lock().unwrap(); let max_height = context.chain.max_height(); diff --git a/src/web_ui.rs b/src/web_ui.rs index 3f3be5c..8e286b5 100644 --- a/src/web_ui.rs +++ b/src/web_ui.rs @@ -42,7 +42,7 @@ pub fn run_interface(context: Arc>, miner: Arc>) { .size(1023, 720) .min_size(773, 350) .resizable(true) - .debug(false) + .debug(true) .user_data(()) .invoke_handler(|web_view, arg| { debug!("Command {}", arg); @@ -306,7 +306,9 @@ fn action_loaded(context: &Arc>, web_view: &mut WebView<()>) { if index > 0 { c.bus.post(Event::BlockchainChanged { index }); } - if let Ok(zones) = serde_json::to_string(&c.chain.get_zones()) { + let zones = c.chain.get_zones(); + info!("Loaded zones: {:?}", &zones); + if let Ok(zones) = serde_json::to_string(&zones) { let _ = web_view.eval(&format!("zonesChanged('{}');", &zones)); } event_info(web_view, "Application loaded"); diff --git a/src/webview/index.html b/src/webview/index.html index 0b16e35..5486368 100644 --- a/src/webview/index.html +++ b/src/webview/index.html @@ -4,8 +4,8 @@ ALFIS - {styles} {scripts} + {styles} diff --git a/src/webview/scripts.js b/src/webview/scripts.js index d806627..14ec826 100644 --- a/src/webview/scripts.js +++ b/src/webview/scripts.js @@ -438,11 +438,8 @@ function keystoreChanged(path, pub_key, hash) { public_key_field.value = pub_key; public_key_field.title = path + "\n" + hash; - var save_key = document.getElementById("save_key"); - save_key.disabled = false; - - var new_domain = document.getElementById("new_domain"); - new_domain.disabled = false; + var save_key = document.getElementById("save_key").disabled = false; + var new_domain = document.getElementById("new_domain").disabled = false; } function closeZonesDropdown() { diff --git a/src/x_zones.rs b/src/x_zones.rs deleted file mode 100644 index e0af438..0000000 --- a/src/x_zones.rs +++ /dev/null @@ -1,41 +0,0 @@ -use std::collections::HashSet; -use crate::blockchain::hash_utils::hash_identity; - -pub struct ExternalZones { - zones: HashSet, - hashes: HashSet -} - -impl ExternalZones { - pub fn new() -> Self { - let mut zones: HashSet<_> = include_str!("../iana-tlds.txt") - .split("\n") - .map(String::from) - .collect(); - let mut hashes: HashSet<_> = include_str!("../iana-hashes.txt") - .split("\n") - .map(String::from) - .collect(); - let open_nic: HashSet<_> = include_str!("../other-tlds.txt") - .split("\n") - .map(String::from) - .collect(); - for zone in open_nic.iter() { - if zone.is_empty() || zone.starts_with("#") { - continue; - } - zones.insert(zone.to_string()); - hashes.insert(hash_identity(zone, None).to_string()); - } - - Self { zones, hashes } - } - - pub fn has_zone(&self, zone: &str) -> bool { - self.zones.contains(zone) - } - - pub fn has_hash(&self, hash: &str) -> bool { - self.hashes.contains(hash) - } -} \ No newline at end of file