diff --git a/src/blockchain/chain.rs b/src/blockchain/chain.rs index bcb97b0..1e9f103 100644 --- a/src/blockchain/chain.rs +++ b/src/blockchain/chain.rs @@ -756,6 +756,10 @@ impl Chain { } // Check if yggdrasil only property of zone is not violated if let Some(block_data) = transaction.get_domain_data() { + if block_data.records.len() > MAX_RECORDS { + warn!("Someone mined too many records!"); + return Bad; + } let zones = self.get_zones(); for z in zones { if z.name == block_data.zone { @@ -765,6 +769,12 @@ impl Chain { warn!("Someone mined domain with clearnet records for Yggdrasil only zone!"); return Bad; } + if let Some(data) = record.get_data() { + if data.len() > MAX_DATA_LEN { + warn!("Someone mined too long record!"); + return Bad; + } + } } } } diff --git a/src/commons/constants.rs b/src/commons/constants.rs index a7569f6..74356d5 100644 --- a/src/commons/constants.rs +++ b/src/commons/constants.rs @@ -26,6 +26,8 @@ pub const BLOCK_SIGNERS_START_RANDOM: i64 = 180; pub const NEW_DOMAINS_INTERVAL: i64 = 86400; // One day in seconds pub const DOMAIN_LIFETIME: i64 = 86400 * 365; // One year +pub const MAX_RECORDS: usize = 30; +pub const MAX_DATA_LEN: usize = 255; pub const DB_NAME: &str = "blockchain.db"; pub const CLASS_ORIGIN: &str = "origin"; @@ -34,7 +36,7 @@ pub const ALFIS_DEBUG: &str = "ALFIS_DEBUG"; /// Public nodes listen port pub const LISTEN_PORT: u16 = 4244; -pub const UI_REFRESH_DELAY_MS: u128 = 250; +pub const UI_REFRESH_DELAY_MS: u128 = 500; pub const LOG_REFRESH_DELAY_SEC: u64 = 60; pub const POLL_TIMEOUT: Option = Some(Duration::from_millis(250)); diff --git a/src/dns/protocol.rs b/src/dns/protocol.rs index 4d38f47..97e09ac 100644 --- a/src/dns/protocol.rs +++ b/src/dns/protocol.rs @@ -533,6 +533,26 @@ impl DnsRecord { } } + pub fn get_data(&self) -> Option { + match *self { + DnsRecord::A { ref addr, .. } => Some(addr.to_string()), + DnsRecord::AAAA { ref addr, .. } => Some(addr.to_string()), + DnsRecord::NS { ref host, .. } => Some(host.clone()), + DnsRecord::CNAME { ref host, .. } => Some(host.clone()), + DnsRecord::SRV { ref host, .. } => Some(host.clone()), + DnsRecord::MX { ref host, .. } => Some(host.clone()), + DnsRecord::TXT { ref data, .. } => Some(data.clone()), + DnsRecord::SOA { ref m_name, ref r_name, .. } => { + let mut result = String::from(m_name); + result.push_str(" @ "); + result.push_str(r_name); + Some(result) + }, + DnsRecord::UNKNOWN { ref domain, .. } => Some(domain.clone()), + DnsRecord::OPT { .. } => None, + } + } + pub fn get_ttl(&self) -> u32 { match *self { DnsRecord::A { diff --git a/src/p2p/network.rs b/src/p2p/network.rs index ba17514..088820f 100644 --- a/src/p2p/network.rs +++ b/src/p2p/network.rs @@ -153,9 +153,8 @@ impl Network { let height = context.chain.get_height(); let nodes = peers.get_peers_active_count(); let banned = peers.get_peers_banned_count(); - if nodes > 0 { - context.bus.post(crate::event::Event::NetworkStatus { nodes, blocks: height }); - } + context.bus.post(crate::event::Event::NetworkStatus { nodes, blocks: height }); + if log_timer.elapsed().as_secs() > LOG_REFRESH_DELAY_SEC { info!("Active nodes count: {}, banned count: {}, blocks count: {}", nodes, banned, height); let elapsed = last_events_time.elapsed().as_secs(); @@ -164,7 +163,7 @@ impl Network { } log_timer = Instant::now(); } - if nodes < MAX_NODES && connect_timer.elapsed().as_secs() >= 10 { + if nodes < MAX_NODES && connect_timer.elapsed().as_secs() >= 5 { peers.connect_new_peers(poll.registry(), &mut unique_token, yggdrasil_only); connect_timer = Instant::now(); } diff --git a/src/web_ui.rs b/src/web_ui.rs index 4660cae..41c74fb 100644 --- a/src/web_ui.rs +++ b/src/web_ui.rs @@ -108,7 +108,15 @@ fn run_interface_loop(context: &mut Arc>, interface: &mut WebView fn action_check_record(web_view: &mut WebView<()>, data: String) { match serde_json::from_str::(&data) { - Ok(_) => { web_view.eval("recordOkay(true)").expect("Error evaluating!"); } + Ok(record) => { + if let Some(string) = record.get_data() { + if string.len() > MAX_DATA_LEN { + web_view.eval("recordOkay(false)").expect("Error evaluating!"); + } else { + web_view.eval("recordOkay(true)").expect("Error evaluating!"); + } + } + } Err(e) => { web_view.eval("recordOkay(false)").expect("Error evaluating!"); dbg!(e); } } } @@ -361,6 +369,11 @@ fn action_create_domain(context: Arc>, miner: Arc>, return; } }; + if data.records.len() > MAX_RECORDS { + show_warning(web_view, "Too many records. Mining more than 30 records not allowed."); + let _ = web_view.eval("domainMiningUnavailable();"); + return; + } // Check if yggdrasil only quality of zone is not violated let zones = context.chain.get_zones(); for z in zones { diff --git a/src/webview/index.html b/src/webview/index.html index 444b929..e583aaf 100644 --- a/src/webview/index.html +++ b/src/webview/index.html @@ -122,7 +122,7 @@
-
Connecting...
+
No connection