Added record constraints.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Duration> = Some(Duration::from_millis(250));
|
||||
|
||||
@@ -533,6 +533,26 @@ impl DnsRecord {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_data(&self) -> Option<String> {
|
||||
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 {
|
||||
|
||||
+3
-4
@@ -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();
|
||||
}
|
||||
|
||||
+14
-1
@@ -108,7 +108,15 @@ fn run_interface_loop(context: &mut Arc<Mutex<Context>>, interface: &mut WebView
|
||||
|
||||
fn action_check_record(web_view: &mut WebView<()>, data: String) {
|
||||
match serde_json::from_str::<DnsRecord>(&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<Mutex<Context>>, miner: Arc<Mutex<Miner>>,
|
||||
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 {
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item">
|
||||
<div id="status_bar_left">Connecting...</div>
|
||||
<div id="status_bar_left">No connection</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user